-2

I am using Js code inbetween php. I am trying make the body empty and append php text for every loop. php code works fine, but js works only when php has completed the script fully. Someone Please help

<?php
    while($row = $result->fetch_assoc()){

            $count++;
            $email = "";
            $email = $row['email_id'];
            $result_row_count = $result->num_rows; 
            ?>

            <script type ="text/javascript">
            $(document).ready(function(){
            $("body").empty();
            });
            </script>

            <?php
            echo '<h4> Sending Mails '.$count.' of '.$result_row_count.' ---     '.$email.'</h4>';
            flush();
            ob_flush();
            sleep(1);
    ?>
4
  • $(document).ready(function(){})...remove this and just use $("body").empty(); But it's not a good way of doing things. Commented Aug 12, 2016 at 12:25
  • 2
    php runs on the server, creates the necessary content and send it back to the web server. The web page waits for the web server to deliver the requested page. The browser executes any scripts that need to be run. Can you see why your code will not work? Commented Aug 12, 2016 at 12:26
  • Thank you so much....... I tried using so many ways. I want to show updated list of php...but nothing worked till now.... Thanks a lot. Commented Aug 12, 2016 at 12:27
  • Possible duplicate of Executing javascript within PHP Commented Aug 12, 2016 at 12:35

1 Answer 1

1
<script type ="text/javascript">$("body").empty();</script>

use this code

Sign up to request clarification or add additional context in comments.

3 Comments

For the sake of futre readers, can you explain why this works?
$(document).ready(function(){ }); this function working only after page loading complete. and you trying to use this function in between loop. loop working multiple times but not with page refresh.
Please edit the answer instead of explaining in the comments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.