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 ...
随机推荐
- Codeforces Round #620 (Div. 2)D dilworld定理
题:https://codeforces.com/contest/1304/problem/D 题意:给定长度为n-1的只含’>'和‘<’的字符串,让你构造出俩个排列,俩个排列相邻的数字之 ...
- 2020/1/28 PHP代码审计之代码执行漏洞
0x00代码执行原理 应用程序在调用一些能够将字符串转换为代码的函数(如PHP中的eval)时,没有考虑用户是否控制这个字符串,将造成代码执行漏洞. 该漏洞主要存在于eval().assert().p ...
- Linux-线程同步之互斥锁
1.互斥锁又叫互斥量(mutex) 2.相关函数:pthread_mutex_init pthread_mutex_destroy pthread_mutex_lock pthread_mute ...
- 论 <解方程>
题面: 求n次整系数方程\(\sum_{i=1}^{n} a_ix^i = 0\)在区间\([1,m]\)上的整数解 解法: 1.暴力 O(NM) 暴力枚举+解方程 2.假设只要求一个解 瞎搞做法 引 ...
- Dynamics CRM - 在 C# Plugin 里以 System Administrator 权限来更新 Entity
场景说明: 1.在使用 CRM 系统时,经常会有需要在某个 Entity 下对其他 Entity 的 Record 进行更新,或者在 post 中对自身进行更新,这里就需要用到 SDK 上的 upda ...
- 24.docker 部署 wordPress
1. 拉取远程 mysql 和 wordpress 镜像 并 启动起来 使用 docker pull mysql:5.7.27 docker pull wordpress 2. 创建mysql 的 c ...
- thinkCMF图片上传选择已上传图片
1.找到上传图片的模板页面 webuploader.html 在上传文件标签后面 添加 <li class=""><a href="#explorer& ...
- PAT Advanced 1089 Insert or Merge (25) [two pointers]
题目 According to Wikipedia: Insertion sort iterates, consuming one input element each repetition, and ...
- jmlr论文下载
下载脚本 #!/bin/bash # down_jmlr.sh ver=$1 wget http://www.jmlr.org/papers/$ver/ -O index.htm cat index. ...
- Overlapping generations model
I.6 Overlapping generations 世代被分离开,世代不重复一定满足哈代公式的条件,但是现实情况远没有这么简单(因为会世代重叠,即亲代死去同时一个亲代在不同时间都有可能产生子代,因 ...