나는 PHP 파일을 통해 mysql 데이터베이스의 일부 데이터를 수정하기 위해 Ajax를 사용하고있다. php 파일이 "OK"또는 "ERROR"를 울릴 수 있도록 코드를 작성했습니다. 나는 경고 (ret)로 체크하고 잘 작동하고있다. 하지만 문제는 if (ret == "OK")입니다. 이 성명서 안에 들어 가지 않습니다. 아무도 나를 도울 수 있습니까?If 문을 사용하는 Ajax ResponseText
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementById('Store_cards_action_form_close').click();
ret = xmlhttp.responseText;
if (ret=="OK"){
alert("Congratulations. Transaction Successful.");
document.location.reload();
}
else{
alert("You have Insufficient Coins to buy this Card!");
}
}
}
xmlhttp.open("GET","script_card_transaction.php?" + para,true);
xmlhttp.send();
를 들어 당신은 아마 당신의 응답 텍스트 주위에 약간의 공백이있다. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim – Phil