XHRHTTPRequest响应不能等于普通字符串

时间:2012-04-18 00:04:39

标签: php javascript ajax jquery if-statement

我正在尝试将成功字符串与xhr.responseText进行比较,但它不起作用,我不知道为什么。

if (xhr.responseText == "success")
{
    alert("Yay");
}

可能是什么原因?我试图提醒responseTest,它具有完全相同的值,“成功”。

2 个答案:

答案 0 :(得分:1)

我打赌那里还有别的东西。最好使用console.log而不是alert。现代浏览器内置了一个控制台。

alert(escape(xhr.responseText));

这将显示警报中不可见的其他字符。

答案 1 :(得分:0)

如果您是开发人员,我认为您正在使用firebug处理firefox,请尝试打印xhr.response对象以使用以下句子调试脚本:      的console.log(xhr.responseText);