3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.2.1
11 * Copyright(c) 2006-2010 Ext JS, Inc.
13 * http://www.extjs.com/license
16 * Portions of this file are based on pieces of Yahoo User Interface Library
17 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
18 * YUI licensed under the BSD License:
19 * http://developer.yahoo.net/yui/license.txt
21 Ext.lib.Ajax = function() {
22 var activeX = ['MSXML2.XMLHTTP.3.0',
25 CONTENTTYPE = 'Content-Type';
28 function setHeader(o) {
32 function setTheHeaders(conn, headers){
33 for (prop in headers) {
34 if (headers.hasOwnProperty(prop)) {
35 conn.setRequestHeader(prop, headers[prop]);
40 if (pub.defaultHeaders) {
41 setTheHeaders(conn, pub.defaultHeaders);
45 setTheHeaders(conn, pub.headers);
51 function createExceptionObject(tId, callbackArg, isAbort, isTimeout) {
54 status : isAbort ? -1 : 0,
55 statusText : isAbort ? 'transaction aborted' : 'communication failure',
58 argument : callbackArg
63 function initHeader(label, value) {
64 (pub.headers = pub.headers || {})[label] = value;
68 function createResponseObject(o, callbackArg) {
74 // see: https://prototype.lighthouseapp.com/projects/8886/tickets/129-ie-mangles-http-response-status-code-204-to-1223
75 isBrokenStatus = conn.status == 1223;
78 headerStr = o.conn.getAllResponseHeaders();
79 Ext.each(headerStr.replace(/\r\n/g, '\n').split('\n'), function(v){
82 s = v.substr(0, t).toLowerCase();
83 if(v.charAt(t + 1) == ' '){
86 headerObj[s] = v.substr(t + 1);
93 // Normalize the status and statusText when IE returns 1223, see the above link.
94 status : isBrokenStatus ? 204 : conn.status,
95 statusText : isBrokenStatus ? 'No Content' : conn.statusText,
96 getResponseHeader : function(header){return headerObj[header.toLowerCase()];},
97 getAllResponseHeaders : function(){return headerStr},
98 responseText : conn.responseText,
99 responseXML : conn.responseXML,
100 argument : callbackArg
105 function releaseObject(o) {
107 pub.conn[o.tId] = null;
114 function handleTransactionResponse(o, callback, isAbort, isTimeout) {
120 var httpStatus, responseObject;
123 if (o.conn.status !== undefined && o.conn.status != 0) {
124 httpStatus = o.conn.status;
134 if ((httpStatus >= 200 && httpStatus < 300) || (Ext.isIE && httpStatus == 1223)) {
135 responseObject = createResponseObject(o, callback.argument);
136 if (callback.success) {
137 if (!callback.scope) {
138 callback.success(responseObject);
141 callback.success.apply(callback.scope, [responseObject]);
146 switch (httpStatus) {
153 responseObject = createExceptionObject(o.tId, callback.argument, (isAbort ? isAbort : false), isTimeout);
154 if (callback.failure) {
155 if (!callback.scope) {
156 callback.failure(responseObject);
159 callback.failure.apply(callback.scope, [responseObject]);
164 responseObject = createResponseObject(o, callback.argument);
165 if (callback.failure) {
166 if (!callback.scope) {
167 callback.failure(responseObject);
170 callback.failure.apply(callback.scope, [responseObject]);
177 responseObject = null;
181 function handleReadyState(o, callback){
182 callback = callback || {};
186 cbTimeout = callback.timeout || null;
189 pub.conn[tId] = conn;
190 pub.timeout[tId] = setTimeout(function() {
191 pub.abort(o, callback, true);
195 poll[tId] = setInterval(
197 if (conn && conn.readyState == 4) {
198 clearInterval(poll[tId]);
202 clearTimeout(pub.timeout[tId]);
203 pub.timeout[tId] = null;
206 handleTransactionResponse(o, callback);
213 function asyncRequest(method, uri, callback, postData) {
214 var o = getConnectionObject() || null;
217 o.conn.open(method, uri, true);
219 if (pub.useDefaultXhrHeader) {
220 initHeader('X-Requested-With', pub.defaultXhrHeader);
223 if(postData && pub.useDefaultHeader && (!pub.headers || !pub.headers[CONTENTTYPE])){
224 initHeader(CONTENTTYPE, pub.defaultPostHeader);
227 if (pub.defaultHeaders || pub.headers) {
231 handleReadyState(o, callback);
232 o.conn.send(postData || null);
238 function getConnectionObject() {
242 if (o = createXhrObject(pub.transactionId)) {
252 function createXhrObject(transactionId) {
256 http = new XMLHttpRequest();
258 for (var i = 0; i < activeX.length; ++i) {
260 http = new ActiveXObject(activeX[i]);
265 return {conn : http, tId : transactionId};
270 request : function(method, uri, cb, data, options) {
273 xmlData = options.xmlData,
274 jsonData = options.jsonData,
277 Ext.applyIf(me, options);
279 if(xmlData || jsonData){
281 if(!hs || !hs[CONTENTTYPE]){
282 initHeader(CONTENTTYPE, xmlData ? 'text/xml' : 'application/json');
284 data = xmlData || (!Ext.isPrimitive(jsonData) ? Ext.encode(jsonData) : jsonData);
287 return asyncRequest(method || options.method || "POST", uri, cb, data);
290 serializeForm : function(form) {
291 var fElements = form.elements || (document.forms[form] || Ext.getDom(form)).elements,
293 encoder = encodeURIComponent,
301 Ext.each(fElements, function(element) {
305 if (!element.disabled && name){
306 if(/select-(one|multiple)/i.test(type)) {
307 Ext.each(element.options, function(opt) {
309 data += String.format("{0}={1}&", encoder(name), encoder((opt.hasAttribute ? opt.hasAttribute('value') : opt.getAttribute('value') !== null) ? opt.value : opt.text));
312 } else if(!/file|undefined|reset|button/i.test(type)) {
313 if(!(/radio|checkbox/i.test(type) && !element.checked) && !(type == 'submit' && hasSubmit)){
315 data += encoder(name) + '=' + encoder(element.value) + '&';
316 hasSubmit = /submit/i.test(type);
321 return data.substr(0, data.length - 1);
324 useDefaultHeader : true,
325 defaultPostHeader : 'application/x-www-form-urlencoded; charset=UTF-8',
326 useDefaultXhrHeader : true,
327 defaultXhrHeader : 'XMLHttpRequest',
334 // This is never called - Is it worth exposing this?
335 // setProgId : function(id) {
336 // activeX.unshift(id);
339 // This is never called - Is it worth exposing this?
340 // setDefaultPostHeader : function(b) {
341 // this.useDefaultHeader = b;
344 // This is never called - Is it worth exposing this?
345 // setDefaultXhrHeader : function(b) {
346 // this.useDefaultXhrHeader = b;
349 // This is never called - Is it worth exposing this?
350 // setPollingInterval : function(i) {
351 // if (typeof i == 'number' && isFinite(i)) {
352 // this.pollInterval = i;
356 // This is never called - Is it worth exposing this?
357 // resetDefaultHeaders : function() {
358 // this.defaultHeaders = null;
361 abort : function(o, callback, isTimeout) {
366 if (me.isCallInProgress(o)) {
368 clearInterval(me.poll[tId]);
370 clearTimeout(pub.timeout[tId]);
371 me.timeout[tId] = null;
373 handleTransactionResponse(o, callback, (isAbort = true), isTimeout);
378 isCallInProgress : function(o) {
379 // if there is a connection and readyState is not 0 or 4
380 return o.conn && !{0:true,4:true}[o.conn.readyState];