jQuery的getScript加入脚本函数永远不会失败? [英] jquery getScript function never fails?
本文介绍了jQuery的getScript加入脚本函数永远不会失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
jQuery的getScript加入失败函数永远不会被调用。看到这个小提琴: http://jsfiddle.net/getsetbro/8xNMs/
The jQuery getScript fail function is never called. See this fiddle: http://jsfiddle.net/getsetbro/8xNMs/
$.getScript("http://api.jquery.com/scripts/jquery.NO-SUCH-FILE.js").done(function() {
console.log('yep');
}).fail(function() {
console.log('fail function does not fire fine');
});
和完整的功能不会被调用: http://jsfiddle.net/getsetbro/ns6yQ/
And the complete function is never called: http://jsfiddle.net/getsetbro/ns6yQ/
$.ajax({
url: url,
type: 'get',
crossDomain: true,
dataType: 'script',
async:false,
cache:false,
success: function(result) {
console.log('SUCCESS');
},
error: function(result) {
console.log('ERROR');
},
complete: function(result) {
console.log('COMPLETE');
}
})
哦,在IE浏览器,它实际上触发成功,并完成时,它会失败的。 = [
Oh, and in IE it actually fires SUCCESS and COMPLETE when it should have failed. =[
推荐答案
.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 element fires no errors and such.
但它确定为同一个域。 http://jsfiddle.net/8xNMs/2/
But it's ok for same domain. http://jsfiddle.net/8xNMs/2/
这篇关于jQuery的getScript加入脚本函数永远不会失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文