Delay in receiving Ajax results using jQuery
I have a simple jQuery Ajax call which gets HTML results from a PHP file (which just executes a mysql query and formats the results in a list). The problem I'm having though is that this whole Ajax call takes about 12s to execute (the 'Waiting for Response' time in Firebug is 12.3s), but when I just load the PHP page wit开发者_JAVA百科h the same URL parameters in my browser, the whole page is loaded in about 300ms (and when I just run the SQL query that the PHP file calls, it takes under 1ms).
Some other notes which may help:
- The size of the Ajax data is 2kb, so I don't think its due to that.
- The data takes much quicker to load (about 4.3s) if the same ajax call is done with the same parameters after its been run once before already (even though I have the Cache-Control for the page set to: private, no-store, no-cache, must-revalidate, post-check=0, pre-check=0)
Here is the jQuery source code for the ajax call:
$.ajax({
url: "./lib/hippofunctions.php",
type: "GET",
dataType: "html",
data:
{
"ajax_action" : "get_hippos_for_tags",
"curTags" : currentCheckedTags,
"sortBy" : sortBy,
"params" : checkedFriendsStr,
"location" : location,
"start" : start
},
error: function(request){my_alert("error on ajax_getHipposfortags ")},
success:function(data){
$("#HippoContainer_inner").html(data);
}
})
}
any thoughts or suggestions why its taking so long to receive the Ajax data and how I can speed this up?
I'll update this with more suggestions, but for now do some performance testing on the success function:
success:function(data){
console.time("data render");
$("#HippoContainer_inner").html(data);
console.timeEnd("data render");
}
精彩评论