Skip to content
This repository was archived by the owner on Nov 27, 2018. It is now read-only.

Creating an AJAX request

avoidwork edited this page Apr 22, 2013 · 7 revisions

Creating an AJAX request

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.

Simple GET

If you want to make a GET request to a resource, do the following:

"http://www.somedomain.com/resource123".get(function (arg) {
	
});

Advanced GET

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",});

Elements can GET too!

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");
});

Clone this wiki locally