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:
<button type="button" id="submitAddTeamButton" dojoType="dijit.form.Button">Add Team
<script type="dojo/method" event="onClick" args="evt">
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!