Skip to content

Commit 78e5641

Browse files
committed
ajax docs
1 parent 8be67bd commit 78e5641

File tree

1 file changed

+39
-21
lines changed

1 file changed

+39
-21
lines changed

ajax.js

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,45 @@ var parseURI = require('../../js/parse-uri/parse-uri');
55
var param = require("../../js/param/param");
66

77
/**
8-
@module {function} can-util/dom/ajax/ajax ajax
9-
@parent can-util/dom
10-
@signature `ajax(settings)`
11-
@param {Object} settings Configuration options for the AJAX request.
12-
The list of configuration options is the same as for [jQuery.ajax](http://api.jquery.com/jQuery.ajax/#jQuery-ajax-settings).
13-
@return {Promise} A Promise that resolves to the data. The Promise instance is abortable and exposes an `abort` method.
14-
Invoking abort on the Promise instance indirectly rejects it.
15-
16-
@body
17-
`ajax( settings )` is used to make an asynchronous HTTP (AJAX) request
18-
similar to [http://api.jquery.com/jQuery.ajax/jQuery.ajax]. The example below
19-
makes use of [can-util/dom/frag/frag].
20-
21-
ajax({
22-
url: 'http://canjs.com/docs/can.ajax.html',
23-
success: function(document) {
24-
var frag = can.frag(document);
25-
return frag.querySelector(".heading h1").innerText; //-> ajax
26-
}
27-
});
28-
8+
* @module {function} can-util/dom/ajax/ajax ajax
9+
* @parent can-util/dom
10+
*
11+
* Make an asynchronous HTTP (AJAX) request.
12+
*
13+
* @signature `ajax( ajaxOptions )`
14+
*
15+
* Is used to make an asynchronous HTTP (AJAX) request similar to [http://api.jquery.com/jQuery.ajax/jQuery.ajax].
16+
*
17+
* ```
18+
* var ajax = require("can-util/dom/ajax/ajax");
19+
*
20+
* ajax({
21+
* url: "http://query.yahooapis.com/v1/public/yql",
22+
* data: {
23+
* format: "json",
24+
* q: 'select * from geo.places where text="sunnyvale, ca"'
25+
* }
26+
* }).then(function(response){
27+
* console.log( response.query.count ); // => 2
28+
* });
29+
* ```
30+
*
31+
* @param {can-util/typedefs/ajaxOptions} ajaxOptions Configuration options for the AJAX request.
32+
* - __url__ {String} The requested url.
33+
* - __type__ {String} The method of the request. Ex: `GET`, `PUT`, `POST`, etc. Capitalization is ignored. Default is `GET`.
34+
* - __data__ {Object} The data of the request. If data needs to be urlencoded (e.g. for GET requests or for CORS) it is serialized with [can-util/js/param].
35+
* - __dataType__ {String} Type of data. Default is `json`.
36+
* - __crossDomain__ {Boolean} If you wish to force a crossDomain request (such as JSONP) on the same domain, set the value of crossDomain to true. This allows, for example, server-side redirection to another domain. Default: `false` for same-domain requests, `true` for cross-domain requests.
37+
* - __timeout__ {Number} Set a timeout (in milliseconds) for the request. A value of 0 means there will be no timeout.
38+
* - __timeoutFn__ {Function} Timeout callback to be called after `xhr.abort()`.
39+
* - __success__ {Function} A function to be called if the request succeeds. The function gets passed one argument based on content type: `xhr.responseText`, `xhr.responseXML` or parsed JSON.
40+
* - __error__ {Function} A function to be called if the request fails. The function receives three arguments: `xhr`, `xhr.status` and `xhr.statusText`.
41+
* - __complete__ {Function} A function to be called when the request finishes (after success and error callbacks are executed). The function gets passed two arguments: `xhr`, `xhr.statusText`.
42+
* - __userAgent__ {String} Default: `XMLHttpRequest`.
43+
* - __lang__ {String} Default `en`.
44+
*
45+
* @return {Promise} A Promise that resolves to the data. The Promise instance is abortable and exposes an `abort` method. Invoking abort on the Promise instance indirectly rejects it.
46+
*
2947
*/
3048

3149
// from https://gist.github.com/mythz/1334560

0 commit comments

Comments
 (0)