git.asbjorn.biz
/
jquery.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Renamed $.ajax's "before"-option to "beforeSend" to prevent conflict with form plugin...
[jquery.git]
/
src
/
ajax
/
ajax.js
diff --git
a/src/ajax/ajax.js
b/src/ajax/ajax.js
index
51f9d60
..
4df372b
100644
(file)
--- a/
src/ajax/ajax.js
+++ b/
src/ajax/ajax.js
@@
-124,7
+124,7
@@
jQuery.fn.extend({
// for some weird reason, it doesn't work if the callback is ommited
jQuery.getScript( this.src );
else {
// for some weird reason, it doesn't work if the callback is ommited
jQuery.getScript( this.src );
else {
- jQuery.eval ( this.text || this.textContent || this.innerHTML || "" );
+ jQuery.globalEval( this.text || this.textContent || this.innerHTML || "" );
}
}).end();
}
}
}).end();
}
@@
-134,10
+134,7
@@
jQuery.fn.extend({
// If IE is used, create a wrapper for the XMLHttpRequest object
if ( jQuery.browser.msie && typeof XMLHttpRequest == "undefined" )
XMLHttpRequest = function(){
// If IE is used, create a wrapper for the XMLHttpRequest object
if ( jQuery.browser.msie && typeof XMLHttpRequest == "undefined" )
XMLHttpRequest = function(){
- return new ActiveXObject(
- navigator.userAgent.indexOf("MSIE 5") >= 0 ?
- "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP"
- );
+ return new ActiveXObject("Microsoft.XMLHTTP");
};
// Attach a bunch of functions for handling common AJAX events
};
// Attach a bunch of functions for handling common AJAX events
@@
-304,6
+301,10
@@
jQuery.extend({
* Loads, and executes, a remote JavaScript file using an HTTP GET request.
* All of the arguments to the method (except URL) are optional.
*
* Loads, and executes, a remote JavaScript file using an HTTP GET request.
* All of the arguments to the method (except URL) are optional.
*
+ * Warning: Safari <= 2.0.x is unable to evalulate scripts in a global
+ * context sychronously. If you load functions via getScript, make sure
+ * to call them after a delay.
+ *
* @example $.getScript("test.js")
*
* @example $.getScript("test.js", function(){
* @example $.getScript("test.js")
*
* @example $.getScript("test.js", function(){
@@
-483,6
+484,9
@@
jQuery.extend({
* (Boolean) async - By default, all requests are send asynchronous (set to true).
* If you need synchronous requests, set this option to false.
*
* (Boolean) async - By default, all requests are send asynchronous (set to true).
* If you need synchronous requests, set this option to false.
*
+ * (Function) beforeSend - A pre-callback to set custom headers etc., the
+ * XMLHttpRequest is passed as the only argument.
+ *
* @example $.ajax({
* type: "GET",
* url: "test.js",
* @example $.ajax({
* type: "GET",
* url: "test.js",
@@
-520,7
+524,8
@@
jQuery.extend({
data: null,
contentType: "application/x-www-form-urlencoded",
processData: true,
data: null,
contentType: "application/x-www-form-urlencoded",
processData: true,
- async: true
+ async: true,
+ beforeSend: null
}, s);
// if data available
}, s);
// if data available
@@
-561,6
+566,10
@@
jQuery.extend({
// Make sure the browser sends the right content length
if ( xml.overrideMimeType )
xml.setRequestHeader("Connection", "close");
// Make sure the browser sends the right content length
if ( xml.overrideMimeType )
xml.setRequestHeader("Connection", "close");
+
+ // Allow custom headers/mimetypes
+ if( s.beforeSend )
+ s.beforeSend(xml);
// Wait for a response to come back
var onreadystatechange = function(isTimeout){
// Wait for a response to come back
var onreadystatechange = function(isTimeout){
@@
-684,7
+693,7
@@
jQuery.extend({
// If the type is "script", eval it in global context
if ( type == "script" ) {
// If the type is "script", eval it in global context
if ( type == "script" ) {
- jQuery.eval( data );
+ jQuery.globalEval( data );
}
// Get the JavaScript object, if JSON is used.
}
// Get the JavaScript object, if JSON is used.
@@
-712,10
+721,10
@@
jQuery.extend({
} else {
// Serialize the key/values
for ( var j in a ) {
} else {
// Serialize the key/values
for ( var j in a ) {
- //if one value is array then treat each array value in part
- if (typeof a[j] == 'object') {
+ // If the value is an array then the key names need to be repeated
+ if( a[j].constructor == Array ) {
for (var k = 0; k < a[j].length; k++) {
for (var k = 0; k < a[j].length; k++) {
- s.push( j + "[]=" + encodeURIComponent( a[j][k] ) );
+ s.push( j + "=" + encodeURIComponent( a[j][k] ) );
}
} else {
s.push( j + "=" + encodeURIComponent( a[j] ) );
}
} else {
s.push( j + "=" + encodeURIComponent( a[j] ) );
@@
-727,10
+736,14
@@
jQuery.extend({
return s.join("&");
},
return s.join("&");
},
- // TODO document me
- eval: function(data) {
+ // evalulates a script in global context
+ // not reliable for safari
+ globalEval: function(data) {
if (window.execScript)
window.execScript( data );
if (window.execScript)
window.execScript( data );
+ else if(jQuery.browser.safari)
+ // safari doesn't provide a synchronous global eval
+ window.setTimeout( data, 0 );
else
eval.call( window, data );
}
else
eval.call( window, data );
}