ajax给全局变量赋值

在用js的flot.js时,$plot方法,要设置x,y轴的数组,这次的x,y轴数组数据由ajax从后台获取,获取变量给其他全局的数组赋值时,发现在$ajax方法外的数据有异常,赋值失败,后发现。在ajax中取消异步,便可赋值。

代码如下:

            $.ajax({
                dataType: "json",
                type: "get",
           //     type: "post",
                url: "../controller/getRecommend.php?name=" + get["name"],
          //      url: "../controller/getRecommend.php",
       //         data:
                async : false,(此为添加行)
                success: function(data) {
                    
            //        console.log(data.length);
                 //   len = data.length;
                    // for (var i = 0; i < data.length; i++) {
                    //     var a = [i,data[i].TotalTime,data[i].hotel];
                    //     d.push(a);

                    // }
                    for(var i=0;i                         data_got.push([i,data[i].TotalTime]);
                        dx.push([i,data[i].hotel]);
                    }
        //            d.length = len;
                },
                error: function() {

                }
            });

你可能感兴趣的:(ajax给全局变量赋值)