jQuery Ajax发布,返回什么类型的数据? [英] Jquery Ajax post, returns what type of data?

查看:157
本文介绍了jQuery Ajax发布,返回什么类型的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发送了一个ajax请求,它返回了单词"false"或"Username".我知道这个工作正常.成功时,它将单词"false"或"Username"放入.body类div中.我遇到的问题是我要检查是否存在"false".这样我的密码字段可以禁用或禁用.问题是一切正常,并经过了测试.我的问题是,当我检查"false"时,它认为它以NULL的形式存在.无论ajax发送什么,它都是外来数据类型,尽管它可以用html显示,但似乎可以将其存储在变量中,并检查是否存在"false".

I sent an ajax request and it either returns the word "false" or "Username". I got this to work fine. On success it puts the word "false" or the "Username" into the .body class div. The problem I am having is that I want to check if "false", or not "false" exists. So that my password field can disable or undisable. The thing is everything works fine and is tested. My issue is that when I check the "false" it thinks that it exists as NULL. Whatever the ajax sends out it is a foreign data type, although it can display it in html, I can seem to then store it in a variable and check if "false" exists.

$(function () {

    $(".Guide_Welcome_Container").hide();
    $("#inputPassword").attr("disabled", "disabled");


    $("button").click(function () {
        $(".Guide_Welcome_Container").fadeToggle(1000);
        $(".HeaderLogin").fadeToggle(1000);
    });

    $("#inputEmail").keyup(function () {
        var UsernameInput = $(this).val();
        $.ajax({
            type: "POST",
            url: "PullUserDb.php",
            data: {
                'UsernameInput': UsernameInput
            },
            dataType: "html",
            success: function (data) {
                $('#BodyID').html(data);
                var GoodUsername = $("#BodyID").html();

                if (GoodUsername != "false") {
                    $("#inputPassword").attr("disabled", "disabled");
                } else {
                    $("#inputPassword").removeAttr("disabled");
                }
                //
            }

        });

    });

});

推荐答案

$("#BodyID").html() //might contain some html too

$("#BodyID").html() //might contain some html too

尝试
console.log($("#BodyID").html());
在您的成功回调中查看返回的结果

Try
console.log($("#BodyID").html());
within your success callback to see what it returns

这篇关于jQuery Ajax发布,返回什么类型的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆