Skip to content

Instantly share code, notes, and snippets.

@mike-gusiev
Last active August 29, 2015 14:21
Show Gist options
  • Save mike-gusiev/9f69eadfda7a00b872ad to your computer and use it in GitHub Desktop.
Save mike-gusiev/9f69eadfda7a00b872ad to your computer and use it in GitHub Desktop.
Vanilla AJAX
//Vanilla JS
var r = new XMLHttpRequest();
r.open("POST", "/path/to/php", true);
r.onreadystatechange = function () {
if (r.readyState != 4 || r.status != 200) return;
console.log("Success: " + r.responseText);
};
r.send("banana=yellow");
//jQuery
$.ajax( {
type: 'POST',
url: '/analytics/goods_feed/?addGoods=1',
data: 'action=3&type=4',
beforeSend: function() {
$('#platforms').addClass('wait');
}
})
.done(function(data) {
console.log(data);
})
.fail(function(data) {
console.log(data);
})
.always(function() {
console.log(data);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment