This repository was archived by the owner on Nov 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Creating an AJAX request
avoidwork edited this page Apr 22, 2013
·
7 revisions
The ideal way to create an AJAX request is to utilize the String.prototype extensions del, headers, get, put, post, options & jsonp.
Each method accepts success, failure, headers & timeout parameters, and returns a Promise.
We'll use GETs for this tutorial.
If you want to make a GET request to a resource, do the following:
"http://www.somedomain.com/resource123".get(function (arg) {
…
});If you want to make a GET request to a resource, with error handling, do the following:
"http://www.somedomain.com/resource123".get(function (arg) {
…
}, function (e) {
…
});If you want to specify custom headers, do the following:
"http://www.somedomain.com/resource123".get(function (arg) {
…
}, function (e) {
…
}, {"Accept" : "application/json", …});Sometimes you want to inject the responseText of an AJAX request directly into a DOM element; abaaso makes this easy!
$("#login").get("/views/login.htm", function () {
this.removeClass("hidden");
}, function (e) {
this.html($.label.error.serverError).removeClass("hidden");
});