私のPHPコードは、AJAX呼び出しに応じて異なる文字列で応答します…その応答をテストしたいのですが、私はそれを行うことができませんでした。私はresponseTextが未定義の型であることを知りましたので、型キャストを試みました:
if (String(xmlhttp.responseText)=="OK")
{
//do something
} else
{
//display the responseText
document.getElementById(spanID).innerHTML=xmlhttp.responseText;
}
表示されるものは何ですか? OK。 (同じ型キャストなしで)。どうして?
ベストアンサー
ここで実際に見ている以上に文字列がない場合は、文字列に空白やその他の印刷できない文字が含まれている必要があります。比較を行う前にトリミングしてみてください。
Edit Also try putting console logging in both your ‘if’
and ‘else’ blocks – maybe your method is being called multiple
times unexpectedly and there is an odd race condition.