-
Notifications
You must be signed in to change notification settings - Fork 20.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #12838: hook point for non-jQuery.ajax synchronous script fetch/execute in domManip #1051
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -194,25 +194,6 @@ jQuery.each( [ "ajaxStart", "ajaxStop", "ajaxComplete", "ajaxError", "ajaxSucces | |
}; | ||
}); | ||
|
||
jQuery.each( [ "get", "post" ], function( i, method ) { | ||
jQuery[ method ] = function( url, data, callback, type ) { | ||
// shift arguments if data argument was omitted | ||
if ( jQuery.isFunction( data ) ) { | ||
type = type || callback; | ||
callback = data; | ||
data = undefined; | ||
} | ||
|
||
return jQuery.ajax({ | ||
url: url, | ||
type: method, | ||
dataType: type, | ||
data: data, | ||
success: callback | ||
}); | ||
}; | ||
}); | ||
|
||
jQuery.extend({ | ||
|
||
// Counter for holding the number of active queries | ||
|
@@ -694,15 +675,34 @@ jQuery.extend({ | |
return jqXHR; | ||
}, | ||
|
||
getScript: function( url, callback ) { | ||
return jQuery.get( url, undefined, callback, "script" ); | ||
}, | ||
|
||
getJSON: function( url, data, callback ) { | ||
return jQuery.get( url, data, callback, "json" ); | ||
}, | ||
|
||
getScript: function( url, callback ) { | ||
return jQuery.get( url, undefined, callback, "script" ); | ||
} | ||
}); | ||
|
||
jQuery.each( [ "get", "post" ], function( i, method ) { | ||
jQuery[ method ] = function( url, data, callback, type ) { | ||
// shift arguments if data argument was omitted | ||
if ( jQuery.isFunction( data ) ) { | ||
type = type || callback; | ||
callback = data; | ||
data = undefined; | ||
} | ||
|
||
return jQuery.ajax({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice use of options to protect from custom converters. |
||
url: url, | ||
type: method, | ||
dataType: type, | ||
data: data, | ||
success: callback | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was this block moved? |
||
}); | ||
}; | ||
}); | ||
|
||
/* Handles responses to an ajax request: | ||
* - finds the right dataType (mediates between content-type and expected dataType) | ||
* - returns the corresponding response | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -334,14 +334,7 @@ jQuery.fn.extend({ | |
|
||
if ( node.src ) { | ||
// Hope ajax is available... | ||
jQuery.ajax({ | ||
url: node.src, | ||
type: "GET", | ||
dataType: "script", | ||
async: false, | ||
global: false, | ||
"throws": true | ||
}); | ||
jQuery._evalUrl( node.src ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. -1, No new API surface. I'm sorry, but we need to find another way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not so much surface API as it is a simple hook. It's clearly marked as private (leading underscore). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is literally impossible to satisfy #12838 without new API surface. We may opt not to do it, but we will not find "another way". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only other way I see is to have a global There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It's not practical. One would be expected to have a build without ajax and be able to use this build with whatever third party ajax lib (or none: I understand rick's reservations with this but I don't think we can offer a practical solution any other way. We can build jQuery without ajax now, so we should provide this hook. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like a script element being created and appended to the Is that incorrect? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, it is incorrect. Transport selection is a bit more involved than a simple one-on-one correspondance with a dataType. You missed the condition here: https://github.com/jquery/jquery/blob/master/src/ajax/script.js#L30 If it's not a crossDomain request, then ajax will continue searching for a suitable transport, until it reaches the one in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if the custom ajax lib doesn't do any of this? Can it just use a script element? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can't load a script using script tag injection synchronously. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I know—thank you—but that's not what I asked. I concede, let's pile more ugly "_" junk onto jQuery. Can't wait for the bug reports. |
||
} else { | ||
jQuery.globalEval( node.textContent.replace( rcleanScript, "" ) ); | ||
} | ||
|
@@ -540,6 +533,17 @@ jQuery.extend({ | |
// Discard any remaining `private` and `user` data | ||
data_discard( elem ); | ||
} | ||
}, | ||
|
||
_evalUrl: function( url ) { | ||
return jQuery.ajax({ | ||
url: url, | ||
type: "GET", | ||
dataType: "text", | ||
async: false, | ||
global: false, | ||
success: jQuery.globalEval | ||
}); | ||
} | ||
}); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this block moved?