-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);
    ?>
Sethu Raja
  • 29
  • 5
  • $(document).ready(function(){})...remove this and just use $("body").empty(); But it's not a good way of doing things. – Mykola Borysyuk Aug 12 '16 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? –  Aug 12 '16 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. – Sethu Raja Aug 12 '16 at 12:27
  • Possible duplicate of [Executing javascript within PHP](http://stackoverflow.com/questions/3971232/executing-javascript-within-php) – underscore_d Aug 12 '16 at 12:35

1 Answers1

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

use this code

Div dotnet
  • 26
  • 4
  • For the sake of futre readers, can you explain why this works? – litelite Aug 12 '16 at 12:43
  • $(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. – Div dotnet Aug 16 '16 at 05:02
  • Please edit the answer instead of explaining in the comments. – litelite Aug 16 '16 at 12:41