Upgrade to ExtJS 3.1.1 - Released 02/08/2010
[extjs.git] / docs / source / Connection.html
1 <html>\r
2 <head>\r
3   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    \r
4   <title>The source code</title>\r
5     <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />\r
6     <script type="text/javascript" src="../resources/prettify/prettify.js"></script>\r
7 </head>\r
8 <body  onload="prettyPrint();">\r
9     <pre class="prettyprint lang-js">(function(){\r
10     var BEFOREREQUEST = "beforerequest",\r
11         REQUESTCOMPLETE = "requestcomplete",\r
12         REQUESTEXCEPTION = "requestexception",\r
13         UNDEFINED = undefined,\r
14         LOAD = 'load',\r
15         POST = 'POST',\r
16         GET = 'GET',\r
17         WINDOW = window;\r
18 \r
19     <div id="cls-Ext.data.Connection"></div>/**\r
20      * @class Ext.data.Connection\r
21      * @extends Ext.util.Observable\r
22      * <p>The class encapsulates a connection to the page's originating domain, allowing requests to be made\r
23      * either to a configured URL, or to a URL specified at request time.</p>\r
24      * <p>Requests made by this class are asynchronous, and will return immediately. No data from\r
25      * the server will be available to the statement immediately following the {@link #request} call.\r
26      * To process returned data, use a\r
27      * <a href="#request-option-success" ext:member="request-option-success" ext:cls="Ext.data.Connection">success callback</a>\r
28      * in the request options object,\r
29      * or an {@link #requestcomplete event listener}.</p>\r
30      * <p><h3>File Uploads</h3><a href="#request-option-isUpload" ext:member="request-option-isUpload" ext:cls="Ext.data.Connection">File uploads</a> are not performed using normal "Ajax" techniques, that\r
31      * is they are <b>not</b> performed using XMLHttpRequests. Instead the form is submitted in the standard\r
32      * manner with the DOM <tt>&lt;form></tt> element temporarily modified to have its\r
33      * <a href="http://www.w3.org/TR/REC-html40/present/frames.html#adef-target">target</a> set to refer\r
34      * to a dynamically generated, hidden <tt>&lt;iframe></tt> which is inserted into the document\r
35      * but removed after the return data has been gathered.</p>\r
36      * <p>The server response is parsed by the browser to create the document for the IFRAME. If the\r
37      * server is using JSON to send the return object, then the\r
38      * <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17">Content-Type</a> header\r
39      * must be set to "text/html" in order to tell the browser to insert the text unchanged into the document body.</p>\r
40      * <p>Characters which are significant to an HTML parser must be sent as HTML entities, so encode\r
41      * "&lt;" as "&amp;lt;", "&amp;" as "&amp;amp;" etc.</p>\r
42      * <p>The response text is retrieved from the document, and a fake XMLHttpRequest object\r
43      * is created containing a <tt>responseText</tt> property in order to conform to the\r
44      * requirements of event handlers and callbacks.</p>\r
45      * <p>Be aware that file upload packets are sent with the content type <a href="http://www.faqs.org/rfcs/rfc2388.html">multipart/form</a>\r
46      * and some server technologies (notably JEE) may require some custom processing in order to\r
47      * retrieve parameter names and parameter values from the packet content.</p>\r
48      * @constructor\r
49      * @param {Object} config a configuration object.\r
50      */\r
51     Ext.data.Connection = function(config){\r
52         Ext.apply(this, config);\r
53         this.addEvents(\r
54             <div id="event-Ext.data.Connection-beforerequest"></div>/**\r
55              * @event beforerequest\r
56              * Fires before a network request is made to retrieve a data object.\r
57              * @param {Connection} conn This Connection object.\r
58              * @param {Object} options The options config object passed to the {@link #request} method.\r
59              */\r
60             BEFOREREQUEST,\r
61             <div id="event-Ext.data.Connection-requestcomplete"></div>/**\r
62              * @event requestcomplete\r
63              * Fires if the request was successfully completed.\r
64              * @param {Connection} conn This Connection object.\r
65              * @param {Object} response The XHR object containing the response data.\r
66              * See <a href="http://www.w3.org/TR/XMLHttpRequest/">The XMLHttpRequest Object</a>\r
67              * for details.\r
68              * @param {Object} options The options config object passed to the {@link #request} method.\r
69              */\r
70             REQUESTCOMPLETE,\r
71             <div id="event-Ext.data.Connection-requestexception"></div>/**\r
72              * @event requestexception\r
73              * Fires if an error HTTP status was returned from the server.\r
74              * See <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html">HTTP Status Code Definitions</a>\r
75              * for details of HTTP status codes.\r
76              * @param {Connection} conn This Connection object.\r
77              * @param {Object} response The XHR object containing the response data.\r
78              * See <a href="http://www.w3.org/TR/XMLHttpRequest/">The XMLHttpRequest Object</a>\r
79              * for details.\r
80              * @param {Object} options The options config object passed to the {@link #request} method.\r
81              */\r
82             REQUESTEXCEPTION\r
83         );\r
84         Ext.data.Connection.superclass.constructor.call(this);\r
85     };\r
86 \r
87     Ext.extend(Ext.data.Connection, Ext.util.Observable, {\r
88         <div id="cfg-Ext.data.Connection-url"></div>/**\r
89          * @cfg {String} url (Optional) <p>The default URL to be used for requests to the server. Defaults to undefined.</p>\r
90          * <p>The <code>url</code> config may be a function which <i>returns</i> the URL to use for the Ajax request. The scope\r
91          * (<code><b>this</b></code> reference) of the function is the <code>scope</code> option passed to the {@link #request} method.</p>\r
92          */\r
93         <div id="cfg-Ext.data.Connection-extraParams"></div>/**\r
94          * @cfg {Object} extraParams (Optional) An object containing properties which are used as\r
95          * extra parameters to each request made by this object. (defaults to undefined)\r
96          */\r
97         <div id="cfg-Ext.data.Connection-defaultHeaders"></div>/**\r
98          * @cfg {Object} defaultHeaders (Optional) An object containing request headers which are added\r
99          *  to each request made by this object. (defaults to undefined)\r
100          */\r
101         <div id="cfg-Ext.data.Connection-method"></div>/**\r
102          * @cfg {String} method (Optional) The default HTTP method to be used for requests.\r
103          * (defaults to undefined; if not set, but {@link #request} params are present, POST will be used;\r
104          * otherwise, GET will be used.)\r
105          */\r
106         <div id="cfg-Ext.data.Connection-timeout"></div>/**\r
107          * @cfg {Number} timeout (Optional) The timeout in milliseconds to be used for requests. (defaults to 30000)\r
108          */\r
109         timeout : 30000,\r
110         <div id="cfg-Ext.data.Connection-autoAbort"></div>/**\r
111          * @cfg {Boolean} autoAbort (Optional) Whether this request should abort any pending requests. (defaults to false)\r
112          * @type Boolean\r
113          */\r
114         autoAbort:false,\r
115 \r
116         <div id="cfg-Ext.data.Connection-disableCaching"></div>/**\r
117          * @cfg {Boolean} disableCaching (Optional) True to add a unique cache-buster param to GET requests. (defaults to true)\r
118          * @type Boolean\r
119          */\r
120         disableCaching: true,\r
121 \r
122         <div id="cfg-Ext.data.Connection-disableCachingParam"></div>/**\r
123          * @cfg {String} disableCachingParam (Optional) Change the parameter which is sent went disabling caching\r
124          * through a cache buster. Defaults to '_dc'\r
125          * @type String\r
126          */\r
127         disableCachingParam: '_dc',\r
128 \r
129         <div id="method-Ext.data.Connection-request"></div>/**\r
130          * <p>Sends an HTTP request to a remote server.</p>\r
131          * <p><b>Important:</b> Ajax server requests are asynchronous, and this call will\r
132          * return before the response has been received. Process any returned data\r
133          * in a callback function.</p>\r
134          * <pre><code>\r
135 Ext.Ajax.request({\r
136    url: 'ajax_demo/sample.json',\r
137    success: function(response, opts) {\r
138       var obj = Ext.decode(response.responseText);\r
139       console.dir(obj);\r
140    },\r
141    failure: function(response, opts) {\r
142       console.log('server-side failure with status code ' + response.status);\r
143    }\r
144 });\r
145          * </code></pre>\r
146          * <p>To execute a callback function in the correct scope, use the <tt>scope</tt> option.</p>\r
147          * @param {Object} options An object which may contain the following properties:<ul>\r
148          * <li><b>url</b> : String/Function (Optional)<div class="sub-desc">The URL to\r
149          * which to send the request, or a function to call which returns a URL string. The scope of the\r
150          * function is specified by the <tt>scope</tt> option. Defaults to the configured\r
151          * <tt>{@link #url}</tt>.</div></li>\r
152          * <li><b>params</b> : Object/String/Function (Optional)<div class="sub-desc">\r
153          * An object containing properties which are used as parameters to the\r
154          * request, a url encoded string or a function to call to get either. The scope of the function\r
155          * is specified by the <tt>scope</tt> option.</div></li>\r
156          * <li><b>method</b> : String (Optional)<div class="sub-desc">The HTTP method to use\r
157          * for the request. Defaults to the configured method, or if no method was configured,\r
158          * "GET" if no parameters are being sent, and "POST" if parameters are being sent.  Note that\r
159          * the method name is case-sensitive and should be all caps.</div></li>\r
160          * <li><b>callback</b> : Function (Optional)<div class="sub-desc">The\r
161          * function to be called upon receipt of the HTTP response. The callback is\r
162          * called regardless of success or failure and is passed the following\r
163          * parameters:<ul>\r
164          * <li><b>options</b> : Object<div class="sub-desc">The parameter to the request call.</div></li>\r
165          * <li><b>success</b> : Boolean<div class="sub-desc">True if the request succeeded.</div></li>\r
166          * <li><b>response</b> : Object<div class="sub-desc">The XMLHttpRequest object containing the response data.\r
167          * See <a href="http://www.w3.org/TR/XMLHttpRequest/">http://www.w3.org/TR/XMLHttpRequest/</a> for details about\r
168          * accessing elements of the response.</div></li>\r
169          * </ul></div></li>\r
170          * <li><a id="request-option-success"></a><b>success</b> : Function (Optional)<div class="sub-desc">The function\r
171          * to be called upon success of the request. The callback is passed the following\r
172          * parameters:<ul>\r
173          * <li><b>response</b> : Object<div class="sub-desc">The XMLHttpRequest object containing the response data.</div></li>\r
174          * <li><b>options</b> : Object<div class="sub-desc">The parameter to the request call.</div></li>\r
175          * </ul></div></li>\r
176          * <li><b>failure</b> : Function (Optional)<div class="sub-desc">The function\r
177          * to be called upon failure of the request. The callback is passed the\r
178          * following parameters:<ul>\r
179          * <li><b>response</b> : Object<div class="sub-desc">The XMLHttpRequest object containing the response data.</div></li>\r
180          * <li><b>options</b> : Object<div class="sub-desc">The parameter to the request call.</div></li>\r
181          * </ul></div></li>\r
182          * <li><b>scope</b> : Object (Optional)<div class="sub-desc">The scope in\r
183          * which to execute the callbacks: The "this" object for the callback function. If the <tt>url</tt>, or <tt>params</tt> options were\r
184          * specified as functions from which to draw values, then this also serves as the scope for those function calls.\r
185          * Defaults to the browser window.</div></li>\r
186          * <li><b>timeout</b> : Number (Optional)<div class="sub-desc">The timeout in milliseconds to be used for this request. Defaults to 30 seconds.</div></li>\r
187          * <li><b>form</b> : Element/HTMLElement/String (Optional)<div class="sub-desc">The <tt>&lt;form&gt;</tt>\r
188          * Element or the id of the <tt>&lt;form&gt;</tt> to pull parameters from.</div></li>\r
189          * <li><a id="request-option-isUpload"></a><b>isUpload</b> : Boolean (Optional)<div class="sub-desc"><b>Only meaningful when used\r
190          * with the <tt>form</tt> option</b>.\r
191          * <p>True if the form object is a file upload (will be set automatically if the form was\r
192          * configured with <b><tt>enctype</tt></b> "multipart/form-data").</p>\r
193          * <p>File uploads are not performed using normal "Ajax" techniques, that is they are <b>not</b>\r
194          * performed using XMLHttpRequests. Instead the form is submitted in the standard manner with the\r
195          * DOM <tt>&lt;form></tt> element temporarily modified to have its\r
196          * <a href="http://www.w3.org/TR/REC-html40/present/frames.html#adef-target">target</a> set to refer\r
197          * to a dynamically generated, hidden <tt>&lt;iframe></tt> which is inserted into the document\r
198          * but removed after the return data has been gathered.</p>\r
199          * <p>The server response is parsed by the browser to create the document for the IFRAME. If the\r
200          * server is using JSON to send the return object, then the\r
201          * <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17">Content-Type</a> header\r
202          * must be set to "text/html" in order to tell the browser to insert the text unchanged into the document body.</p>\r
203          * <p>The response text is retrieved from the document, and a fake XMLHttpRequest object\r
204          * is created containing a <tt>responseText</tt> property in order to conform to the\r
205          * requirements of event handlers and callbacks.</p>\r
206          * <p>Be aware that file upload packets are sent with the content type <a href="http://www.faqs.org/rfcs/rfc2388.html">multipart/form</a>\r
207          * and some server technologies (notably JEE) may require some custom processing in order to\r
208          * retrieve parameter names and parameter values from the packet content.</p>\r
209          * </div></li>\r
210          * <li><b>headers</b> : Object (Optional)<div class="sub-desc">Request\r
211          * headers to set for the request.</div></li>\r
212          * <li><b>xmlData</b> : Object (Optional)<div class="sub-desc">XML document\r
213          * to use for the post. Note: This will be used instead of params for the post\r
214          * data. Any params will be appended to the URL.</div></li>\r
215          * <li><b>jsonData</b> : Object/String (Optional)<div class="sub-desc">JSON\r
216          * data to use as the post. Note: This will be used instead of params for the post\r
217          * data. Any params will be appended to the URL.</div></li>\r
218          * <li><b>disableCaching</b> : Boolean (Optional)<div class="sub-desc">True\r
219          * to add a unique cache-buster param to GET requests.</div></li>\r
220          * </ul></p>\r
221          * <p>The options object may also contain any other property which might be needed to perform\r
222          * postprocessing in a callback because it is passed to callback functions.</p>\r
223          * @return {Number} transactionId The id of the server transaction. This may be used\r
224          * to cancel the request.\r
225          */\r
226         request : function(o){\r
227             var me = this;\r
228             if(me.fireEvent(BEFOREREQUEST, me, o)){\r
229                 if (o.el) {\r
230                     if(!Ext.isEmpty(o.indicatorText)){\r
231                         me.indicatorText = '<div class="loading-indicator">'+o.indicatorText+"</div>";\r
232                     }\r
233                     if(me.indicatorText) {\r
234                         Ext.getDom(o.el).innerHTML = me.indicatorText;\r
235                     }\r
236                     o.success = (Ext.isFunction(o.success) ? o.success : function(){}).createInterceptor(function(response) {\r
237                         Ext.getDom(o.el).innerHTML = response.responseText;\r
238                     });\r
239                 }\r
240 \r
241                 var p = o.params,\r
242                     url = o.url || me.url,\r
243                     method,\r
244                     cb = {success: me.handleResponse,\r
245                           failure: me.handleFailure,\r
246                           scope: me,\r
247                           argument: {options: o},\r
248                           timeout : o.timeout || me.timeout\r
249                     },\r
250                     form,\r
251                     serForm;\r
252 \r
253 \r
254                 if (Ext.isFunction(p)) {\r
255                     p = p.call(o.scope||WINDOW, o);\r
256                 }\r
257 \r
258                 p = Ext.urlEncode(me.extraParams, Ext.isObject(p) ? Ext.urlEncode(p) : p);\r
259 \r
260                 if (Ext.isFunction(url)) {\r
261                     url = url.call(o.scope || WINDOW, o);\r
262                 }\r
263 \r
264                 if((form = Ext.getDom(o.form))){\r
265                     url = url || form.action;\r
266                      if(o.isUpload || /multipart\/form-data/i.test(form.getAttribute("enctype"))) {\r
267                          return me.doFormUpload.call(me, o, p, url);\r
268                      }\r
269                     serForm = Ext.lib.Ajax.serializeForm(form);\r
270                     p = p ? (p + '&' + serForm) : serForm;\r
271                 }\r
272 \r
273                 method = o.method || me.method || ((p || o.xmlData || o.jsonData) ? POST : GET);\r
274 \r
275                 if(method === GET && (me.disableCaching && o.disableCaching !== false) || o.disableCaching === true){\r
276                     var dcp = o.disableCachingParam || me.disableCachingParam;\r
277                     url = Ext.urlAppend(url, dcp + '=' + (new Date().getTime()));\r
278                 }\r
279 \r
280                 o.headers = Ext.apply(o.headers || {}, me.defaultHeaders || {});\r
281 \r
282                 if(o.autoAbort === true || me.autoAbort) {\r
283                     me.abort();\r
284                 }\r
285 \r
286                 if((method == GET || o.xmlData || o.jsonData) && p){\r
287                     url = Ext.urlAppend(url, p);\r
288                     p = '';\r
289                 }\r
290                 return (me.transId = Ext.lib.Ajax.request(method, url, cb, p, o));\r
291             }else{\r
292                 return o.callback ? o.callback.apply(o.scope, [o,UNDEFINED,UNDEFINED]) : null;\r
293             }\r
294         },\r
295 \r
296         <div id="method-Ext.data.Connection-isLoading"></div>/**\r
297          * Determine whether this object has a request outstanding.\r
298          * @param {Number} transactionId (Optional) defaults to the last transaction\r
299          * @return {Boolean} True if there is an outstanding request.\r
300          */\r
301         isLoading : function(transId){\r
302             return transId ? Ext.lib.Ajax.isCallInProgress(transId) : !! this.transId;\r
303         },\r
304 \r
305         <div id="method-Ext.data.Connection-abort"></div>/**\r
306          * Aborts any outstanding request.\r
307          * @param {Number} transactionId (Optional) defaults to the last transaction\r
308          */\r
309         abort : function(transId){\r
310             if(transId || this.isLoading()){\r
311                 Ext.lib.Ajax.abort(transId || this.transId);\r
312             }\r
313         },\r
314 \r
315         // private\r
316         handleResponse : function(response){\r
317             this.transId = false;\r
318             var options = response.argument.options;\r
319             response.argument = options ? options.argument : null;\r
320             this.fireEvent(REQUESTCOMPLETE, this, response, options);\r
321             if(options.success){\r
322                 options.success.call(options.scope, response, options);\r
323             }\r
324             if(options.callback){\r
325                 options.callback.call(options.scope, options, true, response);\r
326             }\r
327         },\r
328 \r
329         // private\r
330         handleFailure : function(response, e){\r
331             this.transId = false;\r
332             var options = response.argument.options;\r
333             response.argument = options ? options.argument : null;\r
334             this.fireEvent(REQUESTEXCEPTION, this, response, options, e);\r
335             if(options.failure){\r
336                 options.failure.call(options.scope, response, options);\r
337             }\r
338             if(options.callback){\r
339                 options.callback.call(options.scope, options, false, response);\r
340             }\r
341         },\r
342 \r
343         // private\r
344         doFormUpload : function(o, ps, url){\r
345             var id = Ext.id(),\r
346                 doc = document,\r
347                 frame = doc.createElement('iframe'),\r
348                 form = Ext.getDom(o.form),\r
349                 hiddens = [],\r
350                 hd,\r
351                 encoding = 'multipart/form-data',\r
352                 buf = {\r
353                     target: form.target,\r
354                     method: form.method,\r
355                     encoding: form.encoding,\r
356                     enctype: form.enctype,\r
357                     action: form.action\r
358                 };\r
359 \r
360             Ext.fly(frame).set({\r
361                 id: id,\r
362                 name: id,\r
363                 cls: 'x-hidden'\r
364 \r
365             });\r
366 \r
367             doc.body.appendChild(frame);\r
368 \r
369             //Reset the Frame to neutral domain\r
370             Ext.fly(frame).set({\r
371                src : Ext.SSL_SECURE_URL\r
372             });\r
373 \r
374             // This is required so that IE doesn't pop the response up in a new window.\r
375             if(Ext.isIE){\r
376                document.frames[id].name = id;\r
377             }\r
378 \r
379 \r
380             Ext.fly(form).set({\r
381                 target: id,\r
382                 method: POST,\r
383                 enctype: encoding,\r
384                 encoding: encoding,\r
385                 action: url || buf.action\r
386             });\r
387 \r
388             // add dynamic params\r
389             Ext.iterate(Ext.urlDecode(ps, false), function(k, v){\r
390                 hd = doc.createElement('input');\r
391                 Ext.fly(hd).set({\r
392                     type: 'hidden',\r
393                     value: v,\r
394                     name: k\r
395                 });\r
396                 form.appendChild(hd);\r
397                 hiddens.push(hd);\r
398             });\r
399 \r
400             function cb(){\r
401                 var me = this,\r
402                     // bogus response object\r
403                     r = {responseText : '',\r
404                          responseXML : null,\r
405                          argument : o.argument},\r
406                     doc,\r
407                     firstChild;\r
408 \r
409                 try{\r
410                     doc = frame.contentWindow.document || frame.contentDocument || WINDOW.frames[id].document;\r
411                     if(doc){\r
412                         if(doc.body){\r
413                             if(/textarea/i.test((firstChild = doc.body.firstChild || {}).tagName)){ // json response wrapped in textarea\r
414                                 r.responseText = firstChild.value;\r
415                             }else{\r
416                                 r.responseText = doc.body.innerHTML;\r
417                             }\r
418                         }\r
419                         //in IE the document may still have a body even if returns XML.\r
420                         r.responseXML = doc.XMLDocument || doc;\r
421                     }\r
422                 }\r
423                 catch(e) {}\r
424 \r
425                 Ext.EventManager.removeListener(frame, LOAD, cb, me);\r
426 \r
427                 me.fireEvent(REQUESTCOMPLETE, me, r, o);\r
428 \r
429                 function runCallback(fn, scope, args){\r
430                     if(Ext.isFunction(fn)){\r
431                         fn.apply(scope, args);\r
432                     }\r
433                 }\r
434 \r
435                 runCallback(o.success, o.scope, [r, o]);\r
436                 runCallback(o.callback, o.scope, [o, true, r]);\r
437 \r
438                 if(!me.debugUploads){\r
439                     setTimeout(function(){Ext.removeNode(frame);}, 100);\r
440                 }\r
441             }\r
442 \r
443             Ext.EventManager.on(frame, LOAD, cb, this);\r
444             form.submit();\r
445 \r
446             Ext.fly(form).set(buf);\r
447             Ext.each(hiddens, function(h) {\r
448                 Ext.removeNode(h);\r
449             });\r
450         }\r
451     });\r
452 })();\r
453 \r
454 <div id="cls-Ext.Ajax"></div>/**\r
455  * @class Ext.Ajax\r
456  * @extends Ext.data.Connection\r
457  * <p>The global Ajax request class that provides a simple way to make Ajax requests\r
458  * with maximum flexibility.</p>\r
459  * <p>Since Ext.Ajax is a singleton, you can set common properties/events for it once\r
460  * and override them at the request function level only if necessary.</p>\r
461  * <p>Common <b>Properties</b> you may want to set are:<div class="mdetail-params"><ul>\r
462  * <li><b><tt>{@link #method}</tt></b><p class="sub-desc"></p></li>\r
463  * <li><b><tt>{@link #extraParams}</tt></b><p class="sub-desc"></p></li>\r
464  * <li><b><tt>{@link #url}</tt></b><p class="sub-desc"></p></li>\r
465  * </ul></div>\r
466  * <pre><code>\r
467 // Default headers to pass in every request\r
468 Ext.Ajax.defaultHeaders = {\r
469     'Powered-By': 'Ext'\r
470 };\r
471  * </code></pre>\r
472  * </p>\r
473  * <p>Common <b>Events</b> you may want to set are:<div class="mdetail-params"><ul>\r
474  * <li><b><tt>{@link Ext.data.Connection#beforerequest beforerequest}</tt></b><p class="sub-desc"></p></li>\r
475  * <li><b><tt>{@link Ext.data.Connection#requestcomplete requestcomplete}</tt></b><p class="sub-desc"></p></li>\r
476  * <li><b><tt>{@link Ext.data.Connection#requestexception requestexception}</tt></b><p class="sub-desc"></p></li>\r
477  * </ul></div>\r
478  * <pre><code>\r
479 // Example: show a spinner during all Ajax requests\r
480 Ext.Ajax.on('beforerequest', this.showSpinner, this);\r
481 Ext.Ajax.on('requestcomplete', this.hideSpinner, this);\r
482 Ext.Ajax.on('requestexception', this.hideSpinner, this);\r
483  * </code></pre>\r
484  * </p>\r
485  * <p>An example request:</p>\r
486  * <pre><code>\r
487 // Basic request\r
488 Ext.Ajax.{@link Ext.data.Connection#request request}({\r
489    url: 'foo.php',\r
490    success: someFn,\r
491    failure: otherFn,\r
492    headers: {\r
493        'my-header': 'foo'\r
494    },\r
495    params: { foo: 'bar' }\r
496 });\r
497 \r
498 // Simple ajax form submission\r
499 Ext.Ajax.{@link Ext.data.Connection#request request}({\r
500     form: 'some-form',\r
501     params: 'foo=bar'\r
502 });\r
503  * </code></pre>\r
504  * </p>\r
505  * @singleton\r
506  */\r
507 Ext.Ajax = new Ext.data.Connection({\r
508     <div id="cfg-Ext.Ajax-url"></div>/**\r
509      * @cfg {String} url @hide\r
510      */\r
511     <div id="cfg-Ext.Ajax-extraParams"></div>/**\r
512      * @cfg {Object} extraParams @hide\r
513      */\r
514     <div id="cfg-Ext.Ajax-defaultHeaders"></div>/**\r
515      * @cfg {Object} defaultHeaders @hide\r
516      */\r
517     <div id="cfg-Ext.Ajax-method"></div>/**\r
518      * @cfg {String} method (Optional) @hide\r
519      */\r
520     <div id="cfg-Ext.Ajax-timeout"></div>/**\r
521      * @cfg {Number} timeout (Optional) @hide\r
522      */\r
523     <div id="cfg-Ext.Ajax-autoAbort"></div>/**\r
524      * @cfg {Boolean} autoAbort (Optional) @hide\r
525      */\r
526 \r
527     <div id="cfg-Ext.Ajax-disableCaching"></div>/**\r
528      * @cfg {Boolean} disableCaching (Optional) @hide\r
529      */\r
530 \r
531     <div id="prop-Ext.Ajax-disableCaching"></div>/**\r
532      * @property  disableCaching\r
533      * True to add a unique cache-buster param to GET requests. (defaults to true)\r
534      * @type Boolean\r
535      */\r
536     <div id="prop-Ext.Ajax-url"></div>/**\r
537      * @property  url\r
538      * The default URL to be used for requests to the server. (defaults to undefined)\r
539      * If the server receives all requests through one URL, setting this once is easier than\r
540      * entering it on every request.\r
541      * @type String\r
542      */\r
543     <div id="prop-Ext.Ajax-extraParams"></div>/**\r
544      * @property  extraParams\r
545      * An object containing properties which are used as extra parameters to each request made\r
546      * by this object (defaults to undefined). Session information and other data that you need\r
547      * to pass with each request are commonly put here.\r
548      * @type Object\r
549      */\r
550     <div id="prop-Ext.Ajax-defaultHeaders"></div>/**\r
551      * @property  defaultHeaders\r
552      * An object containing request headers which are added to each request made by this object\r
553      * (defaults to undefined).\r
554      * @type Object\r
555      */\r
556     <div id="prop-Ext.Ajax-method"></div>/**\r
557      * @property  method\r
558      * The default HTTP method to be used for requests. Note that this is case-sensitive and\r
559      * should be all caps (defaults to undefined; if not set but params are present will use\r
560      * <tt>"POST"</tt>, otherwise will use <tt>"GET"</tt>.)\r
561      * @type String\r
562      */\r
563     <div id="prop-Ext.Ajax-timeout"></div>/**\r
564      * @property  timeout\r
565      * The timeout in milliseconds to be used for requests. (defaults to 30000)\r
566      * @type Number\r
567      */\r
568 \r
569     <div id="prop-Ext.Ajax-autoAbort"></div>/**\r
570      * @property  autoAbort\r
571      * Whether a new request should abort any pending requests. (defaults to false)\r
572      * @type Boolean\r
573      */\r
574     autoAbort : false,\r
575 \r
576     <div id="method-Ext.Ajax-serializeForm"></div>/**\r
577      * Serialize the passed form into a url encoded string\r
578      * @param {String/HTMLElement} form\r
579      * @return {String}\r
580      */\r
581     serializeForm : function(form){\r
582         return Ext.lib.Ajax.serializeForm(form);\r
583     }\r
584 });\r
585 </pre>    \r
586 </body>\r
587 </html>