Skip to content

Instantly share code, notes, and snippets.

@ericwwsun
Created June 26, 2012 21:27
Show Gist options
  • Save ericwwsun/2999231 to your computer and use it in GitHub Desktop.
Save ericwwsun/2999231 to your computer and use it in GitHub Desktop.
Javascript: jQuery ajax example
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