I have the following code where I get an xml file, and convert it into JSON:
showLoading();
$.get(data_file_path, {}, function(content, textStatus, jqXHR){
data_object = jqXHR;
jsonObject = xml2json.parser(data_object.responseText);
hideLoading();
});
Where data_file_path is a .xml file. With this current code, the Loading .gif is not spinning because the xml2json.parser() call is not being doing asynchronously. This is simply a JavaScript Function. Nothing more, nothing less. How can I make this call ALSO Async so that the Loading .gif keeps spinning and then hides normally when the jsonObject is parsed?!
xml2jsonshowLoading()executed) andhideLoading()isn't executed until the callback function passed to$.get()is completed, then the browser is just busy with the code in the callback. There is nothing you can do to set the amount of CPU the browser will dedicate to running the callback; your only option is to optimize the code being executed. If you can provide JSON rather than XML, you can usejQuery.getJSON()instead...