/chrome/community?hl=en
/chrome/community?hl=en
11/16/13
Original Poster
Nathan Tate

NetworkError on synchronous ajax request

Chrome Version (type about:version into your omnibox): 31.0.1650.48 (Official Build 233213)
Operating System (Windows 7/8/Vista/XP, Mac, Linux, Android, iOS): Linux (Ubuntu)
Extensions (type Chrome:extensions into your omnibox): irrelevant
 
I have a single page application that allows users to edit content, and when they try to leave the page, the application saves their content in a synchronous ajax request through jQuery. It was working just fine until recently, and now when I edit the content, and refresh the page, the content doesn't save properly. I dug down to the offending code in jQuery, and it turns out to be XMLHttpRequest. It creates a new XMLHttpRequest, makes several post requests to our own server and to 3rd party services, with asynchronous = false, and when we call .send, it throws a vague network error on us. It only happens within the window.onunload event.
 
I was able to recreate the error with the following code:
 
<html>
<body>
<script>
window.onunload = function() {
try {
var xhr = new XMLHttpRequest();
xhr.open("POST", "/courses/2352959/courseinfo", false);
xhr.send("base-price=15");
console.log(xhr.responseXML);
} catch(e) {
console.log(e, e.stack);
}
};
</script>
</body>
</html>
 
It throws an error on xhr.send and the error has code: 19, NetworkError: a network error has occurred.
 
It's happening on Chrome, Firefox, and on my coworker's Chrome. It seems strange that this is happening.
Community content may not be verified or up-to-date. Learn more.
Recommended Answer
Was this answer helpful?
How can we improve it?
All Replies (20)
Máximo Walsamakis
11/16/13
Máximo Walsamakis
The exact same thing is happening for me.
My code have been working without problems for 10 month, and now the ajax call I make inside onunload its not execute.
 
Here is my code, more or less similar to the other post:
 
[code]
window.onunload = function(e) {

clearInterval(intervalRenewLocks);
$.ajax({
url: url,
type:'POST',
async:false,
data: {
idLockSystem: idLockSystem
}
});
 

};
 
[/code]
 
It works in other browsers, as always, including safari Versión 7.0 (9537.71) and Firefox 25.0.1
11/16/13
Original Poster
Nathan Tate
I was able to verify that this bug was introduced somewhere in Chrome 30. By talking with friends and using Browserstack, the bug is not present in Chrome 29, and while it breaks for me on Chrome 30-beta my client, who has Chrome-30, it didn't break. I had several people upgrade to Chrome 31, and every single one of them went from working to breaking.
Charles.Anderson
11/19/13
Charles.Anderson
We've had exactly the same problem since we upgraded to Chrome 31: a synchronous Ajax request failing during the unload event. Other browsers still working correctly.
Paul Schroeder
11/19/13
Paul Schroeder
We are experiencing this issue too, can someone from Chrome address?
11/19/13
Original Poster
Nathan Tate
I reported an issue and referenced this thread. I suggest you all do the same so we can get their attention. This is a pretty serious bug, as network requests tend to be the most popular use of the onunload event. To report an issue, hit the menu on chrome, and click tools -> report an issue. Reference this thread and maybe they'll notice.
14 MORE
 
This question is locked and replying has been disabled. Still have questions? Ask the Help Community.

Badges

Some community members might have badges that indicate their identity or level of participation in a community.

 
Google Employee — Google product team members and community managers
 
Community Specialist — Google partners who help ensure the quality of community content
 
Platinum Product Expert — Community members with advanced product knowledge who help other Google users and Product Experts
 
Gold Product Expert — Community members with in-depth product knowledge who help other Google users by answering questions
 
Silver Product Expert — Community members with intermediate product knowledge who help other Google users by answering questions
 
Product Expert Alumni — Former Product Experts who are no longer members of the program
Community content may not be verified or up-to-date. Learn more.

Levels

Member levels indicate a user's level of participation in a forum. The greater the participation, the higher the level. Everyone starts at level 1 and can rise to level 10. These activities can increase your level in a forum:

  • Post an answer.
  • Having your answer selected as the best answer.
  • Having your post rated as helpful.
  • Vote up a post.
  • Correctly mark a topic or post as abuse.

Having a post marked and removed as abuse will slow a user's advance in levels.

View profile in forum?

To view this member's profile, you need to leave the current Help page.

Report abuse in forum?

This comment originated in the Google Product Forum. To report abuse, you need to leave the current Help page.

Reply in forum?

This comment originated in the Google Product Forum. To reply, you need to leave the current Help page.

false
Search
Clear search
Close search
Google apps
Main menu
Search Help Center
true
237
false