For this kind of problem, I will have this approach:
- Save the old script that uses
ob_start() and ob_flush() for a user who disables javascript in their browser. - For a user with javascript enabled, upload a predefined amount of content one at a time. To distinguish between js enable user and not, I am thinking of 2 page. The first page displays a link to the old script. Then put the jquery code on this page to intercept the link to the link to the old script, so click on this link to display (or create) a
div , and then load the contents into a div . - You can use
setTimeout to continuously call the AJAX code, and then after reaching a certain condition (Ex, an empty answer), you can delete setTimeout with clearTimeout . Each AJAX request must have an offset parameter, so it will receive content from the last AJAX call. After receiving the response, increase the offset for the next AJAX call. You can use a global variable for this. You can use a simple global variable to prevent an AJAX request from being executed during the last AJAX response to prevent a race condition. Code example:
// lock variable
var is_running = FALSE;
// offset start with 0
var offset = 0;
function load_content ($) {
// check lock
if (! is_running) {
// lock
is_running = true;
// do AJAX
$ .get (URL,
{PARAM},
function (resp) {
// put data to 'div'
// ...
// if empty, then call clearTimeout
// ...
// increase offset here
offset = offset + NUM_ITEM_FETCHED
// release lock
is_running = false;
});
}
}
It should be noted that when using the AJAX call, you must determine the answer manually, since ob_start and ob_flush will not have an effect in this scenario.
Hope this helps you create your own code.
source share