I have a rather extensive PHP page that does a lot of IP address validation for our product licensing. One of those validation routines can take 20-30 seconds, while the bulk of them happen locally and so show up very quickly. I’d like to launch that longer one in a separate jQuery GET, and display it’s results while they review the results of the faster ones.
Here’s the pseudo-code for the “fastchecks” that I’m working from – how/where would a “slowchecks” be launched?
$.ajax(
{
type: "GET",
dataType: "json",
url: "license/fastchecks/" + $("#ipblocks").val(),
error:function (xhr, ajaxOptions, thrownError){
alert("IP Checking Error: " + xhr.status + ": " + thrownError);
},
success: function(fastresults)
{
/* Do stuff with my fast check results while I wait for my slow check results */
}
});
Is this possible? I keep going back to a timed event, but the process itself IS a delay, so that doesn’t seem to make sense to me – am I missing something?
Your code is fine as is. You don’t need to use any timers or anything like that. Your “slowchecks” would be exactly the same as your “fastchecks”. The keyword here is Asynchronous. That
successfunction doesn’t get called until after the ajax call completes. So whatever you wanted to do with the data you get from your ajax call, put it in yoursuccessfunction, and that won’t actually do anything until the results are returned.Also, you would run both Ajax calls at the same time. Each one will run it’s own success function when it completes.