<script>
$.getScript("javascriptfile.js", function(data ){
alert("Script loaded and executed."+data);
});
</script>数据返回未定义。我想要获取javascriptfile.js的响应数据或内容
以下测试不起作用
$.getScript("http://code.jquery.com/jquery-1.9.1.min.js", function(data){
alert("Script loaded and executed."+data);
});发布于 2013-02-07 16:32:11
有个问题
//This one will NOT work
$.getScript("http://jquerymobile.com/branches/popup-widget/js/",
function (data) {
alert("Script loaded and executed." + data);
});
//This one will work
$.getScript("js/jquery.min.js",
function (data) {
alert("Script loaded and executed." + data);
});如果您在域外发出跨域请求,$.getScript()不会提供脚本文件的内容。
发布于 2013-02-07 16:09:44
请运行此程序并回复异常消息,以便我可以与您跟进:
$.getScript("javascriptfile.js")
.done(function(script, textStatus) {
alert(textStatus);
})
.fail(function(jqxhr, settings, exception) {
alert(exception);
});发布于 2013-02-07 16:05:29
我不知道为什么你想要文件的内容,因为getScript会在加载后执行它&如果需要调用函数/插件/任何你刚刚加载的东西,回调只是一个回调;如果你想要文件的内容,那就改用$.get,但不管怎样
do
function(data, textStatus, jqxhr) {
console.log(data); //data returned
console.log(textStatus); //success
console.log(jqxhr.status); //200
console.log('Load was performed.');
});找出“问题”(如果有)(来自http://api.jquery.com/jQuery.getScript/)
https://stackoverflow.com/questions/14746310
复制相似问题