0

I discovered Ajax after a response to my last question and the code provided works fine:

<table class="my-data-table">
    <tr>
        <td class="col-1"></td>
        <td class="col-2"></td>
        <td class="col-3"></td>
    </tr>
</table>
<script>
$.get( "/path_to_table_data.php", function on_table_data_load( data ) {
    $( ".my-data-table .col-3" ).html( data );
});
</script>

This loads the content from the external page when it has completed execution, even though this external page outputs content as it loads.

Is there any way to have the content be returned to the calling page as the content is output by the external page, rather than waiting for it to complete?

Community
  • 1
  • 1
  • waiting for who to complete? your page execution, or ajax execution? – Hüseyin BABAL Jun 11 '14 at 06:22
  • The calling page has finished, waiting for the external page (being loaded by Ajax) to finish loading before the content is displayed with the on_table_data_load call. I would like this function to be called as the data is output by the requested page (path_to_table_data.php), rather than when path_to_table_data.php finishes loading. – user3724406 Jun 11 '14 at 06:25
  • You can do that with php directly. See my answer [here](http://stackoverflow.com/questions/24155869/php-ajax-get-call-return-data-as-output-rather-than-waiting-until-received-a/24156011#24156011) – Hüseyin BABAL Jun 11 '14 at 06:31
  • i think you're looking for to do some [http streaming](http://stackoverflow.com/a/7740859/2593947) – vutran Jun 11 '14 at 06:39

1 Answers1

0

If your data is very big, you can send parital data to client from server instead of using ajax request . While you are processing data on server side, it will be difficult to read partial responses in js side. So, I recommend you to websocket implementation of php. You can see what is Websockets, and have a look at examples in php here

Update: Stream Url

<?php 
    $handle = fopen("path_tu_html_url", "r");
    while (!feof($handle)) { 
        $line = stream_get_line($handle, 1000000, "\n"); 
    } 
?>

This will be on php side

Hüseyin BABAL
  • 15,400
  • 4
  • 51
  • 73
  • This leaves me with my original problem from my previous question. – user3724406 Jun 11 '14 at 06:59
  • The problem in your case, even if your output is very big, php will not let you to print output before it finished output operation. You can use web sockets for this operation to send partial output to client – Hüseyin BABAL Jun 11 '14 at 07:10
  • Do you know of any examples that demonstrate loading a simple html page with streaming? – user3724406 Jun 12 '14 at 03:10