jquery.ajax重复提交出现的error
---IE8不会出现改错误,chrome 会出现
弹出页面重复提交之后,第一次提交进入success,后面的提交进入error。
jqXHR.readyState===0&&jqXHR.status===0
出现问题的原因:
第一次进入success之后,执行了关闭弹出页面的操作,导致浏览器正在关闭窗口,于是浏览器退回了正在执行的ajax请求,并返回readyState=0;
-------------------------------------------------------------
copy:http://www.justinball.com/2013/02/25/jqxhr-returning-readystate-0-and-status-0/
-----------------------------
title:
jqXHR Returning Readystate 0 and Status 0?
content:
I've seen this error a couple of times and I always forget what causes it so for my own sanity I post it here.
If you make an Ajax request and the response comes back with:
statusText: "error" status: 0 readyState: 0
then you likely have one of two problems: 1. You are making a cross domain request and the browser is shutting you down. Check to see if you can turn on CORS or try using JSONP.
- Your Ajax request was triggered via a form submit or clicking on a link and you didn't call e.preventDefault() inside of your event handler. The browser will go ahead and submit the form or follow the link and execute your Ajax code. The form submit or the link follow will win and the browser will immediately terminate your request and give you back a readyState 0.
I ran into the second issue with some Backbone code this evening. In my code the user clicks a button (really a link) and that link saves the model back to the server before traversing to the url specified in the anchor. I know you usually want to protect posts with a form POST but in this case I really do want to follow the url in the link but I need to make sure that the resource existed first and create it if it doesn't. (It's complicated).