Created
June 26, 2012 21:27
-
-
Save ericwwsun/2999231 to your computer and use it in GitHub Desktop.
Javascript: jQuery ajax example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var jqxhr = $j.ajax({ | |
type: 'post', //post or get | |
url: cartUrl, | |
//dataType: 'json', //if necessy | |
data: { product : pid, qty: 1, isAjax: 1 } // Important!! | |
}).done(function(data){ | |
//console.log(data.status); | |
if ( data.status == "SUCCESS") { | |
// do something... | |
} | |
}).fail(function(){ | |
alert("Server error, please try again later."); | |
}).always(function(){ | |
//always do something.... | |
}); | |
jqxhr.always(function() { | |
//second fallback if needed | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment