$ .ajax成功函数返回null

Aru*_*boj 5 php ajax jquery

我有一个基本的登录表单设置,我使用ajax请求将两个变量(登录+密码)发送到另一个页面,该页面检查并相应地返回状态.我的ajax代码

$('form.login_form').on('submit', function(){
    var that = $(this),
    url = "textlogin.php",
    type = that.attr('method'),
    data = {};

    that.find('[name]').each(function(index, value){
        var that = $(this),
        name = that.attr('name'),
        value = that.val();
        data[name] = value;
    });

    $.ajax({
        url: url,
        type: type,
        data: data,

        success: function(response){
            if(response==""){
                $('#login_err').html("its null");
            }else{
                $('#login_err').html(response);
            }
        }
    });
    return false;
});
Run Code Online (Sandbox Code Playgroud)

不起作用,success函数总是返回null.代码工作正常,直到我没有使用ajaxjquery dialog登录.我尝试的事情:1.设置Content-type 2.设置dataType 3.使用$ .post和什么不.

Har*_*tel 0

这是 Ajax 的示例代码。

$.ajax({
        url: "login.php?",
        data:"username="+username+"&password="+password,
        success: function(data)
        {
        }
});
Run Code Online (Sandbox Code Playgroud)

请尝试这个。

如果您使用的是 Mozilla Firefox,请安装 firebug add on 。安装firebug后打开它。现在您可以找到控制台选项卡。将其启用。现在,当你运行 ajax 时,你可以看到这里。

假设你直接传递数组,那么更好的方法是在 php 中使用 implode 函数,所以使用这个函数。

如果有效请给我回复。