English 中文(简体)
为什么我玩笑的阿贾汉温饱和?
原标题:Why does my jQuery AJAX function always return false?
function check_username(){
    $.ajax({
        type: "POST",
        dataType:  json ,
        url: "/ajax/check/username.html",
        data: "via=ajax&username="+$( input[name=register_username] ).val(),
        success: function(msg){
            if(msg.response==false){
                register_username.parent().css( background-color , #db2e24 );
                register_username.parent().parent().find( td:last-child ).text(msg.message);
                register_username.focus();
                return false;
            } else {
                register_username.parent().css( background-color , #fff );
                register_username.parent().parent().find( td:last-child ).text("");
                return true;
            }
       }
    });
}

I m sorry if my English isn t good -- English is not my native language. Back to the topic, why does the function above always return false? FYI : the JSON is OK

最佳回答

<代码>check_username> 系指从网络运行开始然后立即返回的jax功能。 <代码>check_username 早在“jax”打电话结束和成功手稿被打电话之前就返回。 因此,成功手法与<代码>check_username回报的价值有关。

由于在<代码>check_username 上没有回报价值(仅在嵌入式的成功手递功能中),<代码>check_username Returnun specified。 这是一种不实的价值,因此,你认为这永远是虚假的。

如果你想与成功手里的回报价值做一些事情,那么你要么在成功手里工作,要么不得不从成功手里叫另一个功能。 这就是同步行动是如何运作的。

成功手递功能中的“回归代码”false 成功手稿由麻省处理法的内部要求,从成功手稿返回后,就进入阿雅克斯内部的船长。 成功手里的回报价值没有以任何方式使用。

问题回答

问题在于符合逻辑的条件,如:回答不实,不是ool。 你们需要检查反应状况。

如果我不得不猜测,你就任此职,回来的回复是一位智者。 但我想看一下你是否得到有效的回应。 为什么不尝试这样做:

为此:

function check_username()
        {
            $.ajax({
                type: "POST",
                dataType:  json ,
                url: "/ajax/check/username.html",
                data: "via=ajax&username="+$( input[name=register_username] ).val(),
                success: function( msg, textStatus )
                {
                    if ( textStatus == "success" )
                    {
                        register_username.parent().css( background-color , #db2e24 );
                        register_username.parent().parent().find( td:last-child ).text(msg.message);
                        register_username.focus();
                        return false;
                    } else {
                        register_username.parent().css( background-color , #fff );
                        register_username.parent().parent().find( td:last-child ).text("");
                        return true;
                    }
                },
                error: function( jqXHR, textStatus, errorThrown )
                {
                    if ( textStatus == "parsererror" )
                    {
                        alert( "There is an error in your JSON object" );
                    }
                }
            });
        }

你本来可以解决的另一个问题是,你没有返回有效的酒吧,会检查。 如果情况确实如此,添加错误将有助于揭示。

Live demo





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签