In what order does DOJO handles ajax requests?

Posted by mm2887 on Stack Overflow See other posts from Stack Overflow or by mm2887
Published on 2010-05-11T01:09:18Z Indexed on 2010/05/11 1:14 UTC
Read the original article Hit count: 321

Filed under:
|
|
|
|

Hi,

Using a form in a dialog box I am using Dojo in jsp to save the form in my database. After that request is completed using dojo.xhrPost() I am sending in another request to update a dropdown box that should include the added form object that was just saved, but for some reason the request to update the dropdown is executed before saving the form in the database even though the form save is called first. Using Firebug I can see that the getLocations() request is completed before the sendForm() request. This is the code:

Add Team

                    sendForm("ajaxResult1", "addTeamForm");
                    dijit.byId("addTeamDialog").hide();
                    getLocations("locationsTeam");
                </script>

function sendForm(target, form){ var targetNode = dojo.byId(target);

var xhrArgs = {
    form: form,
    url: "ajax",
    handleAs: "text",
    load: function(data) {

        targetNode.innerHTML = data;
    },
    error: function(error) {
        targetNode.innerHTML = "An unexpected error occurred: " + error;
    }

}

//Call the asynchronous xhrGet
var deferred = dojo.xhrPost(xhrArgs);

}

function getLocations(id) { var targetNode = dojo.byId(id);

var xhrArgs = {
    url: "ajax",
    handleAs: "text",
    content: {
        location: "yes"
    },
    load: function(data) {

        targetNode.innerHTML = data;
    },
    error: function(error) {
        targetNode.innerHTML = "An unexpected error occurred: " + error;
    }
}

//Call the asynchronous xhrGet
var deferred = dojo.xhrGet(xhrArgs);

}

Why is this happening? Is there way to make the first request complete first before the second executes?

To reduce the possibilities of why this is happening I tried setting the cache property in xhrGet to false but the result is still the same.

Please help!

© Stack Overflow or respective owner

Related posts about dojo

Related posts about JavaScript