ajax loading 2 XML documents in order without async:false



I am loading 2 XML documents that both run functions on success, although the function for the 2nd XML document is dependant on the 1st being complete.


If I have async:true:



function XmlDataTypes() {

var result = null;
var scriptUrl = "http://ift.tt/16yCsKj" + AccountId;
$.ajax(
{
url: scriptUrl,
type: 'get',
dataType: 'xml',
async: true,
success: function (data) {



},
error: function onXmlError() {
alert("An Error has occurred.");
}

});

return result;


}


The XML data can loaded in a random order so the function for the second document will error if the 1st hasn't completed.


If I set:



async: false


It works correctly but I get a warning:



Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience.


Is there a way around this without using:



async: false

No comments:

Post a Comment