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
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
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
