Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Guard against Webkit's extraneous calls to xhr.onreadystatechange #633
In certain cases Webkit will call the onreadystatechange method of a single XMLHttpRequest object multiple times indicating that it is ready (readyState == 4).
This results in Zepto's 'success' or 'error' methods being called multiple times for the same AJAX request.
This is documented in this thread:
with a jsfiddle here:
and confirmed here:
To reproduce in Zepto:
Expected: you should see 1 alert with the text 'error'
Actual: the alert with the text 'error' occurs 3 times
I'm working to find a way to reproduce this and submit upstream (at least to Chrome -- maybe to Webkit? -- We think it's a Webkit bug since we first observed this issue in Safari on iOS 6).
In the meantime this patch should resolve the issue in Zepto.
 While this is an awkward way to reproduce (clearly a debugger statement shouldn't be in production code) we've observed similar behavior in our production code where success functions are called multiple times for the same AJAX request -- usually when there's a lot going on on the page or the page hasn't completed loading.
The 'debugger' statement was the most reliable way I've seen to approximate these conditions and reproduce the behavior.
I've filed a bug with Chorme based on the info I have:
It references the Webkit reports I've found around the web.
Good luck with your project.