j查询帖子数据返回比较不起作用

jQuery post data return comparison not working

本文关键字:返回 比较 不起作用 数据 查询      更新时间:2023-09-26

我有这段代码:

function addEmail() {
            email = $("#email").val();
            atime = $("select#time").val();
            tid = <?= $tid; ?>;
            $.post("remindme.php", { email: email, time: atime, tid: tid },
                function(data) {
                    if (data == "x") {
                        alert(data);
                        $('#remindme').modal('hide');
                        $('#quota').show();
                    }
                    else {
                        alert(data);
                        $('#remindme').modal('hide');
                        $('#remindersuccess').show();
                    }
                });
            }

remindme.php回声的"x"如果有什么问题。

我正在尝试比较 remindme 的输出.php但即使它回显了 x,条件data == "x"也不起作用。

我添加了alert(data),我可以在需要时正确看到它正确显示x

如果服务器回显x字符串,则成功回调中的if (data == 'x')测试应该可以工作。你的问题在别的地方。

也许迟到了。我遇到了同样的问题,我通过非常愚蠢的解决方法(应用于您的代码)解决了:

function(data) {
    var server_info = data;
    if (server_info == "x") {                       
         $('#remindme').modal('hide');
          $('#quota').show();
    } else {
         $('#remindme').modal('hide');
         $('#remindersuccess').show();
    }
}

我不知道为什么:/

希望对您有所帮助。

我可能遇到了同样的问题,我像这样修复它:

    var verify = function (user,fName,fPass) {
        var result = "";
        $.ajaxSetup({async:false});
        $.post("php_scripts/verify"+user+".php",{login:fName, pass:fPass},function (data) {
            result = $.trim(data);   // use $.trim when are you using "data"
        });
        return result;
    }