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

时间: 2024-10-29 01:12:10

Method POST, Status (canceled) error message的相关文章

Http 错误:&quot;status&quot;:404,&quot;error&quot;:&quot;Not Found&quot;,&quot;message&quot;:&quot;No message available”,”path&quot;:&quot;&quot;

在对代码进行调试的时候,前端页面报了一个错: 1 {"timestamp":"2019-09-02T02:55:45.555+0000","status":404,"error":"Not Found","message":"No message available”,”path":"/order/createorder"} 这个 bug 出现的原

{&quot;error&quot;:&quot;{\&quot;error\&quot;:{\&quot;message\&quot;:\&quot;发送新鲜事超过配额。\&quot;,\&quot;code\&quot;:\&quot;forbidden.FEED_PUBLISH_QUOTA_LIMIT_REACH

今天做 人人的分享的时候遇到: "{"error":"{\"error\":{\"message\":\"发送新鲜事超过配\",\"code\":\"forbidden.FEED_PUBLISH_QUOTA_LIMIT_REACHEL\"}}","status":403}" 原因: 是因为 我的人人的账户:  两天只能  发送

Nginx not running with no error message

Nginx not running with no error message #!/bin/shecho "start"rm /etc/nginx/sites-enabled/defaultln -s /primerbean/nginx_conf/healthbean_nginx.conf /etc/nginx/sites-enabled//etc/init.d/nginx startecho `service nginx status`echo `service apache2 s

Visual Studio Error Message Summary

Error message: JavaScript runtime error: '$' is undefined Solution: index.cshtml 这个页面insert into <script src="~/Scripts/jquery-1.10.2.min.js" type="text/javascript"></script> Error Message: when debug/run a solution, it pop

Citrix 核心服务器报错Error: IMA Service Error Message -2147483647

ima服务不能启动的问题Error: IMA Service Error Message -214748364 http://support.citrix.com/article/CTX032712 可能是C:\Program Files\Citrix\Independent Management Architecture\ imalhc.mdb文件坏了,先删除这个文件.然后运行dsmaint recreatelhc重新创建这个文件.再重新启动机器或者服务,应该可以解决此问题. 日常要备份c:\

Oracle Error - &quot;OCIEnvCreate failed with return code -1 but error message text was not available&quot;.

ISSUE: When trying to connect to an Oracle database you receive the following error: "OCIEnvCreate failed with return code -1 but error message text was not available" CAUSE: 以下两种情况之一是可能的原因: 1,你在 Windows 7 上使用不支持的版本的 Oracle 客户端 (超过 11.2). 2,从以前安

False &#39;Sharing Violation&#39; Xcopy error message

今天想要将QC的新工具自动拷贝到p4 用户机器上使用,为了避免每次通知大家升级啊!!! 于是,我在程序里调用了bat文件,执行拷贝操作,想在默默的情况下替换更新新版本工具,结果我测试发现没能成功更新版本,于是去看log,发现拷贝exe文件的时候报错:Sharing Violation 网上查了很多资料,说的最多的是.拷贝权限问题~~~ 例如:  B -->A.  通常是A处目标不可写,或者B处文件不可读. 查了文件后发现不存在该问题. 当我手动执行bat文件,拷贝顺利进行~~~ 如此诡异~~~

ASP.NET Parser Error Message: Could not load type &#39;Web.Global&#39;.

Server Error in '/myapp' Application. Parser Error Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. P

Pylint Error Message: “E1101: Module &#39;xxx&#39; has no &#39;xxx&#39; member&#39;”

原因:Pylint默认只信任来自标准库stdlib的C扩展,而忽略其他的.模块'xxx'不是stdlib的一部分,需要手动将其添加到白名单. 解决方案: 在terminal里 (例如Windows 平台的powershell)导航到项目所在目录: 为Pylint生成rcfile文件: 1 pylint --generate-rcfile > .pylintrc 打开生成的文件.pylintrc,将模块名添加至白名单:extension-pkg-whitelist=xxx.以 lxml为例,结果为