分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 教程案例

AJAX为canceled

发布时间:2023-09-06 02:25责任编辑:熊小新关键词:暂无标签

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

status=canceled may happen also on ajax requests on JavaScript events:

<script> ?$("#call_ajax").on("click", function(event){ ????$.ajax({ ???????... ????????}); ?});</script><button id="call_ajax">call</button> 

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.

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

<script> ?$("#call_ajax").on("click", function(event){ ????event.preventDefault(); ????$.ajax({ ???????... ????????}); ?});</script>
shareimprove this answer
  • 2
    This saved me, was the problem in my case where I used angular‘s ng-click on a button with type="submit" and then did some networking in the called function. Chrome kept canceling that request...– Robin Jan 6 ‘15 at 13:36
  • 1
    Unfortunately it does not work for me. Any other hints? – Krzysztof Jan 13 ‘16 at 10:10
  •  
    Vaov saved me too! For an angular ng-click event I had nested $http requests and second one was being canceled. After setting the prevent default line it started working again, thanks. – Bahadir Tasdemir Sep 20 ‘16 at 15:03
  •  
    Thanks for this. I knew it was not CORS or a DOM issue. Perhaps @whamma could update their answer to include this as possible cause for completeness :) – glidester Oct 20 ‘17 at 11:15

AJAX为canceled

原文地址:https://www.cnblogs.com/coolgame/p/10075696.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved