美文网首页
jquery ajax从文件中加载json

jquery ajax从文件中加载json

作者: LOOK_LOOK | 来源:发表于2017-04-23 12:23 被阅读61次

async:false

运行结果
  $(function () {
                    $.ajaxSetup({async: false});//指定ajax以同步方式工作
                    var str;//全局变量
                    $.getJSON("js/a.json", function (data) {
                        str = data;//全局变量赋值
                        console.log("async false inner:  " + str)
                    });
                    console.log("async false outer:  " + str);
                });

默认情况

运行结果
  $(function () {
            var str;
            $.getJSON("js/a.json", function (data) {
                str = data;
                console.log("inner:  " + str)
            });
            console.log("outer:  " + str);
        });

相关文章

网友评论

      本文标题:jquery ajax从文件中加载json

      本文链接:https://www.haomeiwen.com/subject/nvtyzttx.html