jquery getScript函数从未失败?
从未调用jQuery getScript fail函数。看这把小提琴: 并且永远不会调用完整的函数:jquery getScript函数从未失败?,jquery,ajax,getscript,Jquery,Ajax,Getscript,从未调用jQuery getScript fail函数。看这把小提琴: 并且永远不会调用完整的函数: 哦,在IE中,当它应该失败时,它实际上激发了成功和完成=[.fail不适用于跨域请求 // Bind script tag hack transport jQuery.ajaxTransport( "script", function(s) { // This transport only deals with cross domain requests if ( s.cr
哦,在IE中,当它应该失败时,它实际上激发了成功和完成=[
.fail
不适用于跨域请求
// Bind script tag hack transport
jQuery.ajaxTransport( "script", function(s) {
// This transport only deals with cross domain requests
if ( s.crossDomain ) {
...
script = document.createElement( "script" );
Script元素不会激发任何错误等
但是对于同一个域也可以。跨域。失败&始终使用jQuery 2.0
$.getScript("http://api.jquery.com/scripts/NO-SUCH-FILE.js")
.done(function() {
console.log("done fired");
}).fail(function() {
console.log("fail fired");
}).always(function() {
console.log("always fired");
});
编辑代码以仅使用
console.log
,因为对Toastr的引用已断开。
// Bind script tag hack transport
jQuery.ajaxTransport( "script", function(s) {
// This transport only deals with cross domain requests
if ( s.crossDomain ) {
...
script = document.createElement( "script" );
$.getScript("http://api.jquery.com/scripts/NO-SUCH-FILE.js")
.done(function() {
console.log("done fired");
}).fail(function() {
console.log("fail fired");
}).always(function() {
console.log("always fired");
});