XHR failed loading: POST

现象  DevTool的 Console报错: VM249 jquery.js:8241 XHR failed loading: POST "http://

现象 

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

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

参考

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