Method POST, Status (canceled) error message
I have the following code which is giving me a Method POST, Status (canceled) error message:
$(document).ready(function() {
var xhr = false;
get_default();
$('#txt1').keyup( function() {
if(xhr && xhr.readyState != 4){
alert("abort");
xhr.abort();
}
if ($("#txt1").val().length >= 2) {
get_data( $("#txt1").val() );
} else {
get_default();
}
});
function get_data( phrase ) {
xhr = $.ajax({
type: 'POST',
url: 'http://intranet/webservices.asmx/GetData',
data: '{phrase: "' + phrase + '"}',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function( results ) {
$("#div1").empty();
if( results.d[0] ) {
$.each( results.d, function( index, result ) {
$("#div1").append( result.Col1 + ' ' + result.Col2 + '<br />' );
});
} else {
alert( "no data available message goes here" );
}
},
error: function(xhr, status, error) {
var err = eval("(" + xhr.responseText + ")");
alert(err.Message) ;
}
});
}
function get_default() {
$('#div1').empty().append("default content goes here.");
}
});
The code actually works as long as each ajax request completes, but if I type fast into txt1, i.e. type the next character before the previous request finishes, I get the error message Method POST, Status (canceled).
Anyone know why this is happening and how to correct the error?
Answer1:
I suppose that the problem is very easy. If you call xhr.abort(); then the error callback of $.ajax will be called for the pending request. So you should just ignore such case inside of error callback. So the error handler can be modified to
error: function(jqXHR, textStatus, errorThrown) {
var err;
if (textStatus !== "abort" && errorThrown !== "abort") {
try {
err = $.parseJSON(jqXHR.responseText);
alert(err.Message);
} catch(e) {
alert("ERROR:\n" + jqXHR.responseText);
}
}
// aborted requests should be just ignored and no error message be displayed
}
P.S. Probably another my old answer on the close problem could also interesting for you.
Answer2:
That is because you are calling abort method which possibly triggers the error handler with appropriate error message.
You can possibly wait for previous ajax request to complete before making the next call.
Answer3:
Ajax is an async type, its not recommonded that u to send request on every keyup event, try the...
async: false
in post method... it'll pause the subsequent posts until the current request done its callback
【转载】http://stackoverflow.com/questions/9928580/method-post-status-canceled-error-message
Method POST, Status (canceled) error message的更多相关文章
- 记一次接口调试错误: {"timestamp":"2019-09-11T03:04:30.036+0000","status":500,"error":"Internal Server Error","message":"Could not write JSON: Object is null; nested exception is com.fasterxml.jackson
接口测试中用postman测试返回是正常的,但是使用其他人去调用就出错了,找了半天,才想起来使用了nginx,用于端口的代理转发.然后根据错误信息发现json格式的某个字段为null,结合日志中的报文 ...
- {"timestamp":"2019-11-12T02:39:28.949+0000","status":415,"error":"Unsupported Media Type","message":"Content type 'text/plain;charset=UTF-8' not supported","path":&quo
在Jmeter运行http请求时报错: {"timestamp":"2019-11-12T02:39:28.949+0000","status&quo ...
- Error message when you try to modify or to delete an alternate access mapping in Windows SharePoint Services 3.0: "An update conflict has occurred, and you must re-try this action"
Article ID: 939308 - View products that this article applies to. Expand all | Collapse all Symptoms ...
- undefined reference to typeinfo - C++ error message
undefined reference to typeinfo - C++ error message There are some compiler and loader error message ...
- Delphi HTTP error message: Can't execute C:\Program Files\Borland\Delphi7\Bin\serverinfo.exe 1813
delphi 调用Webservice ,停止服务的时候总是爱提示: Internal Server ErrorHTTP status code: 500 HTTP error message: C ...
- tomcat已启动,使用maven的deploy发布后,根据路径打开浏览器访问时报错HTTP Status 500 - Error instantiating servlet class
web项目中请求出现错误,如下: HTTP Status 500 - Error instantiating servlet class XXXX类 type Exception report mes ...
- Nginx not running with no error message
Nginx not running with no error message #!/bin/shecho "start"rm /etc/nginx/sites-enabled/d ...
- HTTP Status 500 - Error instantiating servlet class XXXX
问题描述 web项目中请求出现错误,如下: HTTP Status 500 - Error instantiating servlet class XXXX类 type Exception rep ...
- ABAP术语-Error Message
Error Message 原文:http://www.cnblogs.com/qiangsheng/archive/2008/01/30/1058283.html Information from ...
随机推荐
- java8 String intern()
public class Solution { public static void main(String[] args) { String a = new String("he" ...
- Go-并发和并行-协程-信道-缓冲信道-select-mutex-读写文件-beego框架
并发 Go 是并发式语言,而不是并行式语言.在讨论 Go 如何处理并发之前,我们必须理解何为并发,以及并发与并行的区别. 并发是什么? 并发是指立即处理多个任务的能力.一个CPU的情况下<意指看 ...
- h5-FileReader对象的使用
<!--FileReader对象的使用--> <!--需要及时预览 及时:当用户选择完图片之后就立即进行预览处理--onchange事件 预览:通过文件读取对象的readAsData ...
- java数据库连接池比较
dbcp dbcp可能是使用最多的开源连接池,原因大概是因为配置方便,而且很多开源和tomcat应用例子都是使用的这个连接池吧.这个连接池可以设置最大和最小连接,连接等待时间等,基本功能都有.这个连接 ...
- 等和的分隔子集(dp)
晓萌希望将 1 到 N 的连续整数组成的集合划分成两个子集合,且保证每个集合的数字和是相等. 例如,对于 N = 3,对应的集合 1, 2, 3 能被划分成3和1,2两个子集合. 这两个子集合中元素分 ...
- PAT Advanced 1008 Elevator (20) [数学问题-简单数学]
题目 The highest building in our city has only one elevator. A request list is made up with N positive ...
- c#学习笔记03——委托和事件
委托:一种引用类型,这种类型可以用来定义方法签名,从而使用委托实现将方法作为参数传递给其他方法.类似于C++中的函数之争,使用委托使程序员可以将方法引用封装在委托对象内. 定义和声明委托: deleg ...
- 关于SpringMVC的使用总结
简介 springMVC即Spring Web MVC,是spring web模块的一部分,是spring自己的web框架 springMVC对Servlet API 进行了完善的封装,极大的简化了开 ...
- css 传数据套路
<input type=hidden> 那么该标签就不会显示 但是我们可以用这个标签储存数据 这是一个利用标签元素隐藏
- look and say 外观数列的python实现
#look_and_say 外观数列 如果我们把 1 作为Look-and-say 数列的第一项,那么,它的前几项是这样的: 1, 11, 21, 1211, 111221, 312211, 1311 ...