无法将脚本文件加载到另一个脚本文件中 [英] Not able to load the script file inside another script file

查看:96
本文介绍了无法将脚本文件加载到另一个脚本文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在已加载的脚本文件中使用$.getJson();时,无法在另一个脚本文件中加载脚本文件.

Not able to load the script file inside another script file when using $.getJson(); inside the loaded script files.

考虑 fisrt.html :

<script>
$.getScript("second.js",function(){
     // some code here
});
</script>

我的第二个js文件是这样的: second.js:

my second js file is like: second.js:

$.getJSON("somefile.json",function(){
});

second.js 中删除$.getJSON时,文件加载完美,没有任何问题.

When remove the $.getJSON from the second.js the files load perfectly without any problem.

如何用$.getJSON加载json文件?

How can I load the my json file with $.getJSON?

complte json调用:

complte json calling:

$.getJSON('js/offline.json', function(data) {
            alert("success");

        }.error(function(data){
            alert(JSON.stringify(data));
        });

推荐答案

您正在尝试同时使用promise和标准回调API.这就是你想要的.

You're trying to use the promise and standard callback API at the same time. Here's what you want.

$.getJSON("js/offline.json")
  .done(function (data) {
    alert(data);
  })
  .fail(function (err) {
    alert(err);
  });

这篇关于无法将脚本文件加载到另一个脚本文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆