问题
In Firefox, I have a synchronous request that happens (it must be sync or the later JS will not run correctly) now in the XMLHttpReq function it basically changes one of the DIV's contents to a tiny loading logo (turning cog) so you can see progress... In FF this works 100% async or sync... Chrome and IE no such luck..?
Can anyone help me or explain why please? Im guessing it something to do with them disabling ALL other processes but if this is so how can i get this to work OR evaluate and JS file after this original XMLHttpReq has loaded?
回答1:
Is there any reason to use a synchronous XMLHttpRequest?
Synchronous calls tie up your browser until the transaction is finished, which is why it is advised against.
You should look at sequencing your asynchronous calls. Meaning... the problem isn't with your asynchronous call, it's in your reason why it must be sync or the later JS will not run correctly
. Setting a completed
variable in the AJAX callback is pretty simple to do, which the other problematic JS can check before executing.
回答2:
Frame.js is designed to enable synchronous requests without hanging up the browser.
Frame(function(next){
startImageRotation();
next();
});
Frame(function(next){
$.ajax('someUrl.api', {
...
complete: next
});
});
Frame(function(next, response){
// do stuff with ajax response
});
The other commenters are correct in saying that truly synchronous AJAX request are mostly useless because of poor browser support. Frame.js was designed as a solution to that problem. Best luck.
来源:https://stackoverflow.com/questions/7128110/http-synchronous-request-stops-my-gif-moving-in-chrome-and-ie