AJAX REQUEST in request

Go To StackoverFlow.com

0

First I Load php page then a java function Call First AJAX request from JAVA Script which call second php and post some variables and operate function one...Means the first AJAX request is still working...

Now the function one in second php which call another JAVA Script which create another AJAX request which call third php which generate XML data for MAP API...means second AJAX request..but it fails because the first request is still not finished...How can i handle this? Which AJAX call php and that php Call second AJAX request?...

Please Help Me....

Look My Requirement as per your example, Because my code is too long to post and format here as per Stack format

First i load ajax1.php directly in browser.

now I call First AJAX request

$.ajax('/ajax2.php', function(data2){
// But the ajax2.php having Call another AJAX request for ajax3.php which retrive XML Data genereted from mysql and create Google MAP
    $.ajax('/ajax3.php', function(data3){
       // I need to display the ajax2.php Generated MAP to DIV created by ajax1.php
     // Whene I call ajax2.php directy from browser url it AJAX ajax3.php runs and gerete MAP perfectly
     // But I call ajax2.php through ajax1.php AJAX request it dosen't create the ajax3.php AJAX request 
    });
});

In short I call First AJAX request but the First AJAX request Call another Second AJAX request. It generates MAP.

document.getElementById("ntfs").innerHTML=xmlhttp.responseText;
// This above code is not working but I write like

document.write(xmlhttp.responseText);
//This above Code works perfect, but it create new document I can't fill to DIV.innerHTML

Why? happen this?

2012-04-04 17:11
by Pradip Dabhi


0

As always, it would be much easier helping you if you posted some of your own code. I will use jquery.

You need to understand that ajax is asynchronous. The IDE does not wait for an ajax call to be finished in order to execute the next line of code. If you want to have ajax1 call ajax2 when it's done, and ajax2 to call ajax3 when its done, you'll need to utilize the finished: or complete: handler of your ajax technology. in jquery it would look like this...

$.ajax('/ajax1.php', function(data1){
    $.ajax('/ajax2.php', function(data2){
        $.ajax('/ajax3.php', function(data3){
            //All 3 ajax calls are done, in order
        });
    });
});

alert('the first ajax call was made and is probably still executing');

If, for example, you want ajax1 and ajax2 to run at the same time, and have ajax2 call ajax3 when its done, it will look like this...

$.ajax('/ajax1.php', function(data1){
    //ajax1 call is done
});

$.ajax('/ajax2.php', function(data2){
    //ajax2 is done
    $.ajax('/ajax3.php', function(data3){
        //ajax2 and ajax3 calls are done, in order
    });
});

alert('the first 2 ajax call were made and are probably still executing');

Additional Reading: Asynchronous vs. Synchronous

2012-04-04 17:17
by Dutchie432
Ads