我有这段代码:
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;
}