Skip to content

Commit 54867a9

Browse files
committed
jquery ajax: caching repetive conversions/checks for settings.type in $.ajax.
1 parent 31f22f2 commit 54867a9

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/ajax.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,19 +165,20 @@ jQuery.extend({
165165
lastModified: {},
166166

167167
ajax: function( s ) {
168-
var jsonp, jsre = /=\?(&|$)/g, status, data;
169-
170168
// Extend the settings, but re-extend 's' so that it can be
171169
// checked again later (in the test suite, specifically)
172170
s = jQuery.extend(true, s, jQuery.extend(true, {}, jQuery.ajaxSettings, s));
173171

172+
var jsonp, jsre = /=\?(&|$)/g, status, data,
173+
type = s.type.toUpperCase();
174+
174175
// convert data if not already a string
175176
if ( s.data && s.processData && typeof s.data != "string" )
176177
s.data = jQuery.param(s.data);
177178

178179
// Handle JSONP Parameter Callbacks
179180
if ( s.dataType == "jsonp" ) {
180-
if ( s.type.toLowerCase() == "get" ) {
181+
if ( type == "GET" ) {
181182
if ( !s.url.match(jsre) )
182183
s.url += (s.url.match(/\?/) ? "&" : "?") + (s.jsonp || "callback") + "=?";
183184
} else if ( !s.data || !s.data.match(jsre) )
@@ -214,7 +215,7 @@ jQuery.extend({
214215
if ( s.dataType == "script" && s.cache == null )
215216
s.cache = false;
216217

217-
if ( s.cache === false && s.type.toLowerCase() == "get" ) {
218+
if ( s.cache === false && type == "GET" ) {
218219
var ts = now();
219220
// try replacing _= if it is there
220221
var ret = s.url.replace(/(\?|&)_=.*?(&|$)/, "$1_=" + ts + "$2");
@@ -223,7 +224,7 @@ jQuery.extend({
223224
}
224225

225226
// If data is available, append data to url for get requests
226-
if ( s.data && s.type.toLowerCase() == "get" ) {
227+
if ( s.data && type == "GET" ) {
227228
s.url += (s.url.match(/\?/) ? "&" : "?") + s.data;
228229

229230
// IE likes to send both get and post data, prevent this
@@ -239,7 +240,7 @@ jQuery.extend({
239240

240241
// If we're requesting a remote document
241242
// and trying to load JSON or Script with a GET
242-
if ( s.dataType == "script" && s.type.toLowerCase() == "get"
243+
if ( s.dataType == "script" && type == "GET"
243244
&& remote.test(s.url) && remote.exec(s.url)[1] != location.host ){
244245
var head = document.getElementsByTagName("head")[0];
245246
var script = document.createElement("script");
@@ -278,9 +279,9 @@ jQuery.extend({
278279
// Open the socket
279280
// Passing null username, generates a login popup on Opera (#2865)
280281
if( s.username )
281-
xml.open(s.type, s.url, s.async, s.username, s.password);
282+
xml.open(type, s.url, s.async, s.username, s.password);
282283
else
283-
xml.open(s.type, s.url, s.async);
284+
xml.open(type, s.url, s.async);
284285

285286
// Need an extra try/catch for cross domain requests in Firefox 3
286287
try {

0 commit comments

Comments
 (0)