git.asbjorn.biz
/
jquery.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Backported wiki changes from http://docs.jquery.com/API/1.1.1/CSS
[jquery.git]
/
src
/
ajax
/
ajax.js
diff --git
a/src/ajax/ajax.js
b/src/ajax/ajax.js
index
87fe73b
..
814a6b8
100644
(file)
--- a/
src/ajax/ajax.js
+++ b/
src/ajax/ajax.js
@@
-132,7
+132,7
@@
jQuery.fn.extend({
});
// If IE is used, create a wrapper for the XMLHttpRequest object
});
// If IE is used, create a wrapper for the XMLHttpRequest object
-if ( jQuery.browser.msie && typeof XMLHttpRequest == "undefined" )
+if ( !window.XMLHttpRequest )
XMLHttpRequest = function(){
return new ActiveXObject("Microsoft.XMLHTTP");
};
XMLHttpRequest = function(){
return new ActiveXObject("Microsoft.XMLHTTP");
};
@@
-391,6
+391,11
@@
jQuery.extend({
* @cat Ajax
*/
post: function( url, data, callback, type ) {
* @cat Ajax
*/
post: function( url, data, callback, type ) {
+ if ( jQuery.isFunction( data ) ) {
+ callback = data;
+ data = {};
+ }
+
return jQuery.ajax({
type: "POST",
url: url,
return jQuery.ajax({
type: "POST",
url: url,
@@
-594,9
+599,12
@@
jQuery.extend({
if (s.processData && typeof s.data != "string")
s.data = jQuery.param(s.data);
// append data to url for get requests
if (s.processData && typeof s.data != "string")
s.data = jQuery.param(s.data);
// append data to url for get requests
- if( s.type.toLowerCase() == "get" )
+ if( s.type.toLowerCase() == "get" ) {
// "?" + data or "&" + data (in case there are already params)
s.url += ((s.url.indexOf("?") > -1) ? "&" : "?") + s.data;
// "?" + data or "&" + data (in case there are already params)
s.url += ((s.url.indexOf("?") > -1) ? "&" : "?") + s.data;
+ // IE likes to send both get and post data, prevent this
+ s.data = null;
+ }
}
// Watch for a new set of requests
}
// Watch for a new set of requests
@@
-639,6
+647,13
@@
jQuery.extend({
// The transfer is complete and the data is available, or the request timed out
if ( xml && (xml.readyState == 4 || isTimeout == "timeout") ) {
requestDone = true;
// The transfer is complete and the data is available, or the request timed out
if ( xml && (xml.readyState == 4 || isTimeout == "timeout") ) {
requestDone = true;
+
+ // clear poll interval
+ if (ival) {
+ clearInterval(ival);
+ ival = null;
+ }
+
var status;
try {
status = jQuery.httpSuccess( xml ) && isTimeout != "timeout" ?
var status;
try {
status = jQuery.httpSuccess( xml ) && isTimeout != "timeout" ?
@@
-684,11
+699,13
@@
jQuery.extend({
s.complete(xml, status);
// Stop memory leaks
s.complete(xml, status);
// Stop memory leaks
- xml.onreadystatechange = function(){};
- xml = null;
+ if(s.async)
+ xml = null;
}
};
}
};
- xml.onreadystatechange = onreadystatechange;
+
+ // don't attach the handler to the request, just poll it instead
+ var ival = setInterval(onreadystatechange, 13);
// Timeout checker
if ( s.timeout > 0 )
// Timeout checker
if ( s.timeout > 0 )
@@
-703,12
+720,9
@@
jQuery.extend({
}
}, s.timeout);
}
}, s.timeout);
- // save non-leaking reference
- var xml2 = xml;
-
// Send the data
try {
// Send the data
try {
- xml2.send(s.data);
+ xml.send(s.data);
} catch(e) {
jQuery.handleError(s, xml, null, e);
}
} catch(e) {
jQuery.handleError(s, xml, null, e);
}
@@
-718,7
+732,7
@@
jQuery.extend({
onreadystatechange();
// return XMLHttpRequest to allow aborting the request etc.
onreadystatechange();
// return XMLHttpRequest to allow aborting the request etc.
- return xml2;
+ return xml;
},
handleError: function( s, xml, status, e ) {
},
handleError: function( s, xml, status, e ) {
@@
-799,7
+813,7
@@
jQuery.extend({
// Serialize the key/values
for ( var j in a )
// If the value is an array then the key names need to be repeated
// Serialize the key/values
for ( var j in a )
// If the value is an array then the key names need to be repeated
- if ( a[j].constructor == Array )
+ if ( a[j] && a[j].constructor == Array )
jQuery.each( a[j], function(){
s.push( encodeURIComponent(j) + "=" + encodeURIComponent( this ) );
});
jQuery.each( a[j], function(){
s.push( encodeURIComponent(j) + "=" + encodeURIComponent( this ) );
});