问题描述
action page return type is x in PHP 但其他情况会成功
$.ajax({
url: "user.PHP?mysts=chck",type: "POST",data: $("#cntstngfrm").serialize(),success: function (cevap) {
console.log("myrequest = "+cevap);
if (cevap == "x") {
alert("dasdasd");
}else{
alert("999");
}
}
});
user.PHP :
if (isset($_GET['mysts'])=="chck"){
$duzenle=$db->prepare("UPDATE mmb SET
mmbss=:mmbss
WHERE id={$_POST['wqrid']}");
$control=$duzenle->execute(array(
'mmbss'=>$_POST['mmbss']
));
if ($control) {
echo "x";
}else{
echo "y";
}
}
一切正常,但它给出了 999 警报。感谢您的帮助。
解决方法
根据您的第二张图片,有一个换行符 \n
,使用 .trim()
将其删除
success: function (cevap) {
console.log("myrequest = " + cevap);
cevap = cevap.trim(); // <= remove space or newline
if (cevap == "x") {
alert("dasdasd");
}
else {
alert("999");
}
}
或再次检查 user.php
并确保没有其他 echo