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 ...
随机推荐
- 吴裕雄--天生自然MySQL学习笔记:MySQL 创建数据表
创建MySQL数据表需要以下信息: 表名 表字段名 定义每个表字段 语法 以下为创建MySQL数据表的SQL通用语法: CREATE TABLE table_name (column_name col ...
- android stutio 添加依赖
添加依赖有 3种方法: 1 :copy jar 包到libs目录 ,add to library 2: copy aar 文件到libs ,gradle 文件 android 节点添加 repo ...
- dp高难本攻略
903. DI 序列的有效排列 public int numPermsDISequence(String S) { int n=S.length(); int [][]dp=new int [n+1] ...
- [Java-基础] 注解
引言 在进行Spring Boot 入门的时候,主程序需要@SpringBootApplication 来标注一个主程序类,说明这是一个Spring Boot应用.这个的作用是什么?去掉的话会报错.如 ...
- vue多选验证
vue select 多选 验证 <FormItem :prop="'formList.'+index+'.name'" label="姓名" :rule ...
- java android环境变量配置
JAVA_HOME 用于jdk配置D:\Program Files\Java\jdk1.8.0_25 path %JAVA_HOME%\bin;;%JAVA_HOME%\jre\bin;;D:\P ...
- python中的API学习
URL: url是统一资源定位符,对可以从互联网上得到的资源的位置和访问方法的一种简洁的表示,是互联网上标准资源的地址.互联网上的每个文件都有一个唯一的URL,它包含的信息指出文件的位置以及浏览器应该 ...
- PAT Basic 1104 数字⿊洞 (20) [数学问题-简单数学]
题目 给定任⼀个各位数字不完全相同的4位正整数,如果我们先把4个数字按⾮递增排序,再按⾮递减排序,然后⽤第1个数字减第2个数字,将得到⼀个新的数字.⼀直重复这样做,我们很快会停在有"数字⿊洞 ...
- linux 中的.so和.a文件
Linux下的.so是基于Linux下的动态链接,其功能和作用类似与windows下.dll文件. 下面是关于.so的介绍: 一.引言 通常情况下,对函数库的链接是放在编译时期(compile tim ...
- ruoyi IpUtils
package com.ruoyi.common.utils; import java.net.InetAddress; import java.net.UnknownHostException; i ...