XHR failed loading: POST

现象 

DevTool的 Console报错:

VM249 jquery.js:8241 XHR failed loading: POST "http://localhost:8093/api_xxxx".

 send@VM249 jquery.js:8241
 ajax@VM249 jquery.js:7720
 jQuery.(anonymous function)@VM249 jquery.js:7246
 calcProductRate@VM252 api.js:15
 onclick@api:119

 api.js:15

$.post(url, args, function(data) {

DevTool的 Network的报错

XHR 请求的资源 报红色, status  (canceled)

分析
 

按钮的type写成了submit

<input  type="submit" value="查询">

The event successfully sends the request, but is is canceled then (but processed by the server). The reason is, the elements submit forms on click events, no matter if you make any ajax requests on the same click event.

 

解决

1. To prevent request from being cancelled, JavaScript event.preventDefault(); have to be called:

<script>
  $("#call_ajax").on("click", function(event){
     event.preventDefault();
     $.ajax({
        ...    
     });
  });
</script>

 2. 改成button

<input  type="button" value="查询">

参考

https://stackoverflow.com/questions/12009423/what-does-status-canceled-for-a-resource-mean-in-chrome-developer-tools

  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值