Forum Moderators: open

Message Too Old, No Replies

2 ajax functions one after another

         

dave_c00

10:12 am on Sep 24, 2009 (gmt 0)

10+ Year Member



Hi,

I am simply trying to initate 2 ajax scripts on the press of a button. The script simply passes the div id to replace the results and the name of the file to execute.

However, I think as the scripts seem to be running so close together the div ids are getting mixed up and the second results are being put in the first div...

Is there a simple way I can prevent the second ajax script from being run until the first one is completed?

Thanks,

Dave

whoisgregg

1:53 pm on Sep 24, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yup, just put it in a callback of the first ajax script. If you are using Prototype, it would look like this:

 // request 1
new Ajax.Request('/example_script.php', {
method: 'get',
onSuccess: function(transport) {
// request 2, inside of the onSuccess callback
new Ajax.Request('/example_script_2.php', {
method: 'get',
onSuccess: function(transport) { alert('both done!'); }
});
}
});