Added onSuccess and onError callbacks for the $.xml() function.
This commit is contained in:
parent
7ebe209b32
commit
66bd98be22
1 changed files with 18 additions and 1 deletions
19
ajax/ajax.js
19
ajax/ajax.js
|
@ -13,6 +13,15 @@ if ( typeof XMLHttpRequest == 'undefined' && typeof window.ActiveXObject == 'fun
|
||||||
$.xmlActive=0;
|
$.xmlActive=0;
|
||||||
|
|
||||||
$.xml = function( type, url, data, ret ) {
|
$.xml = function( type, url, data, ret ) {
|
||||||
|
if ( !url ) {
|
||||||
|
ret = type.onComplete;
|
||||||
|
var onSuccess = type.onSuccess;
|
||||||
|
var onError = type.onError;
|
||||||
|
data = type.data;
|
||||||
|
url = type.url;
|
||||||
|
type = type.type;
|
||||||
|
}
|
||||||
|
|
||||||
var xml = new XMLHttpRequest();
|
var xml = new XMLHttpRequest();
|
||||||
|
|
||||||
if ( xml ) {
|
if ( xml ) {
|
||||||
|
@ -24,7 +33,8 @@ $.xml = function( type, url, data, ret ) {
|
||||||
// Set header so calling script knows that it's an XMLHttpRequest
|
// Set header so calling script knows that it's an XMLHttpRequest
|
||||||
xml.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
xml.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
||||||
|
|
||||||
/* Force "Connection: close" for Mozilla browsers to work around
|
/* Borrowed from Prototype:
|
||||||
|
* Force "Connection: close" for Mozilla browsers to work around
|
||||||
* a bug where XMLHttpReqeuest sends an incorrect Content-length
|
* a bug where XMLHttpReqeuest sends an incorrect Content-length
|
||||||
* header. See Mozilla Bugzilla #246651.
|
* header. See Mozilla Bugzilla #246651.
|
||||||
*/
|
*/
|
||||||
|
@ -53,6 +63,13 @@ $.xml = function( type, url, data, ret ) {
|
||||||
$.xmlActive = 0
|
$.xmlActive = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( xml.status && xml.status >= 200 && xml.status < 300 ) {
|
||||||
|
if ( onSuccess )
|
||||||
|
onSuccess( xml );
|
||||||
|
} else if ( onError ) {
|
||||||
|
onError( xml );
|
||||||
|
}
|
||||||
|
|
||||||
// Process result
|
// Process result
|
||||||
if ( ret )
|
if ( ret )
|
||||||
ret(xml);
|
ret(xml);
|
||||||
|
|
Loading…
Add table
Reference in a new issue