jquery的响应是正确的,但拾取错误


jquery response is correct but picked up wrong

是否知道为什么下面的代码一直警告为错误,尽管响应返回为hello

它应该提醒为正确

Tnanks

查询

var term = 'jan';
$.ajax(
{
    type : 'POST',
    url  : 'process.php',
    data : 'term=' + term,
    dataType  : 'text',
    timeout   : 600000,
    success   : function(response)
    {
        if (response == 'hello')
        {
            alert('Correct');
        }
        else
        {
            alert('Wrong');
        }
    }
});

PHP

if ($_POST['term'] == 'jan')
{
    echo 'hello';
}
else
{
    echo 'noooo';
}

返回结果中可能存在空白。这可以通过修剪返回结果来解决

var term = 'jan';
$.ajax(
{
    type : 'POST',
    url  : 'process.php',
    data : 'term=' + term,
    dataType  : 'text',
    timeout   : 600000,
    success   : function(response)
    {
        if (response.trim() == 'hello')
        {
            alert('Correct');
        }
        else
        {
            alert('Wrong');
        }
    }
});