ajax jquery - 成功的html响应

时间:2013-02-13 16:30:27

标签: ajax

我有一个ajax表格。我正试图打印成功的相关信息。

所以jquery:

    //start ajax
    $.ajax({
        url: $(this).attr('action'),
        type: "POST",
        data: data,
        cache: false,
        success: function (html) {
            if (html == 1) {
                $('#getquotepopup').fadeTo('slow', 0, function(){$('#cboxLoadingGraphic').remove();});
            } else {
                alert('Sorry, unexpected error. Please try again later.');
            }
        }
    })
接收端

和php:

if (wp_mail($to, $subject, $message)) {
    // the message was sent...
    //for Ajax, create response .OK.
    return 1;
} else {
    return 0;
}

但问题是如果(html == 1)总是被评估为假。

你能指出我的错误吗?

2 个答案:

答案 0 :(得分:0)

尝试使用“=== 1”而不是“== 1”

答案 1 :(得分:-1)

我会从PHP脚本返回一个文本字符串,例如'SUCCESS',而不是1或0。

在此之前,我还会尝试javascript比较,就好像它是一个带引号的字符串:

e.g。

if( html == "1" )
相关问题