This works great at retrieving the php data for say 15 passes BUT when the json file is say 100 items it chokes the php script and creates random errors. My guess is because the requests are all made from this singe ajax request (faster than the php script works) the php script is getting confused?
$(document).ready(function(){
var ajax_load = "<div class='loadwrap'><img class='load' src='/img/load.gif' style='width:12px;' alt='' /> fetching list...</div>";
$("#status").html(ajax_load);
$.getJSON('/fsbo/get_urls_24_hours', function(data) {
$("#alias").fadeOut('slow');
var ajax_load = "<div class='loadwrap'><img class='load' src='/img/load.gif' style='width:12px;' alt='' /> fetching property...</div>";
$('#props').html('');
$.each(data, function(key, val) {
$.ajax({
type: "POST",
url: base_url + "/fsbo/get_property",
data: "url="+ val,
cache:false,
success:
function(data){
$("<div></div>").html(data).appendTo('#props');
}
});
});
});
});
As a side note where do I put the hide loading gif? Putting it at the end of the loop does no good it just opens and closes not waiting for the return of data.
I do think that you have the right answer, that it is because of the call.
The way PHP calls work, is by creating a seperate call to your system, while also invoking various other libraries, therefore invoking a sort of memory leak, which is exponentially increasing the time and resources required.
What I suggest is – pass all of your variables to PHP and let it do the work, then receive a JSON object back, and parse it.
It may be a bit slower to the end user, but should help avoid this from happening.
P.S.
I’ve had similiar issues, when these kinds of calls were making so many requests for one user, that the whole webserver crashed.