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.

  1. 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).

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值