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

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:

 2. 改成button

button" value="查询">

参考

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

你可能感兴趣的:(XHR failed loading: POST)