$.ajax 的async参数在crossdomain跨站下的问题


$.ajax({url:"http://otherdomain.com/another.js",async:false,crossDomain:true,cache:true,dataType:'script',success:function(result){ console.log("aaa"); });
console.log("bbb");

运行这段代码,输出结果的先后顺序会是aaa,再到bbb吗?不是,在跨域的情况下,他们会倒过来,也就是同步没有生效。

$.ajax中的dataType参数具有四种类型:xml, json, script, jsonp, text or html,在这6种类型中,我没有全部测试完,但至少script, jsonp在跨域下面同步是不生效的,要生效的话,可以采用text,取过来js代码后再自己运行。

posted @ 2014-07-24 09:22  BruceZhu  阅读(254)  评论(0编辑  收藏  举报