Grigor
Grigor

Reputation: 4059

jQuery ajax request not cooperating in new version?

I have this code

$.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);
        }
    }
});

and it works fine with http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js version but not the latest one. Is this a problem or there is a new method of doing this?

Upvotes: 0

Views: 93

Answers (1)

Jamie Hutber
Jamie Hutber

Reputation: 28096

If you are posting you will now want to use the .done rather than success.

$.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);
    }
});

Upvotes: 1

Related Questions