来自浏览器的两个并行请求[重复]

Possible Duplicate:
Parallel asynchronous Ajax requests using jQuery

I need to create 2 ajax requests one after the other. And then display the result of the one that has finished first. The problem is that second one always waits for first one to finish. I tried to abort first one but still the second is waiting for first one to finish. Is there any workaround?

Basically first one calls php script that parses some XML file and inserts records into a MySQL table. Second one calls PHP script which needs to return 20 records that first one has imported.

I tried with two ajax calls and the first one called from iframe. But result is always same. Second one is waiting for the first one to finish. Only way around that I find is to create subdomain and call first one with subdomain. But this not working in IE.

Can anybody explain how solve this?

Maybe I need to describe my problem more. First I call ajax that execution time is cca 2 min and while first one is in execution I need to have multiple requests that will retrive records that are imported by first one.

Call them sequentially. After you call the first one, it'll be executing in asynchronous manner. Then you call the second one. At that time first request will be still running. But its not guarranteed that second request will be sent just after first one. So you can have some timeout. See the example bellow.

$.post('ajax/first_call', function(data) {
    // process returned data of first ajax call
});
window.setTimeout(function(){
    $.post('ajax/second_call', function(data) {
        // process returned data of second ajax call
    });
}, 2000);

Here the second ajax call is requested after 2 second. And it does not depend on first call.

You can try to do by using AJAX callback. You can basically enter a nested callback and get the job done. The 1st callback will be invoked when you get the parsed XML and the second one will be called by the 1st callback.

Update for a code example:

var callback2 = function(data)
{
   // Callbacks complete
   // Now do some more stuff
}
var callback1 = function(data)
{
   //do something;
   $.ajax({
    url: '/echo/html/',
    success: function(data) {
        callback2(data);
    }
});   
}
$.ajax({
    url: '/echo/html/',
    success: function(data) {
        callback1(data);
    }
});

In the example above callback2 is invoked when a second Ajax call is complete.