jQuery ajax请求不合作新版本?

时间:2012-01-11 23:18:48

标签: php jquery ajax request

我有这段代码

$.ajax({
    type: "POST",
    url: "test.php",
    data: "id="+id,
    dataType: "json",
    success: function(msg) {
        if(parseInt(msg.status) == 1)
        {
            alert(msg.txt);
        }
        else if(parseInt(msg.status) == 0)
        {
            alert(msg.txt);
        }
    }
});

它适用于http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js版本,但不适用于最新版本。这是一个问题,还是有一种新方法可以做到这一点?

1 个答案:

答案 0 :(得分:1)

如果您要发布,您现在想要使用.done而不是成功。

$.ajax({
type: "POST",
url: "test.php",
dataType: "json",
data: "name=John&location=Boston"
}).done(function( msg ) {

    if(parseInt(msg.status) == 1)
    {
        alert(msg.txt);
    }
    else if(parseInt(msg.status) == 0)
    {
        alert(msg.txt);
    }
});