dreamboy

代码如下:

$(document).ready(function () {       
            var res;
            $.ajax({
                type: \'post\',
                url: \'GridDemo.aspx/PlaceOrder\',
                contentType: "application/json; charset=utf-8",
                dataType: \'json\',
                success: function (results) {
                    var strJSON = results.d; //得到的JSON
                    var obj = eval("(" + strJSON + ")"); //转换后的JSON对象                 
                    res = obj.a;
                    console.log(obj.a);
                },
                error: function () { alert(\'error\'); }
            });
         
            $("#attr01").wijgrid({
                allowSorting: true,
                data: res,              
            });
        });

我理想的是先ajax得到数据,再绑定到控件,可事实是先执行的绑定,后执行ajax方法,js不是按顺序执行吗?

默认情况下JQueryAJAX是异步执行的,所以它在去获取数据的同时也在执行下面的绑定,因为获取数据是需要一定的时间,所以你看到的效果是先绑定后获取数据。只要添加添加async:false.即修改为同步了,具体的代码如下:

 

$.ajax({
   type: \'post\',
   async: false,
   url: \'GridDemo.aspx/PlaceOrder\',
   contentType: "application/json; charset=utf-8",
   dataType: \'json\',

 

分类:

技术点:

相关文章:

  • 2021-11-24
  • 2022-01-04
  • 2021-12-26
  • 2021-05-24
  • 2021-11-05
  • 2021-07-31
  • 2021-09-07
  • 2021-07-21
猜你喜欢
  • 2021-09-25
  • 2021-09-25
  • 2021-09-25
  • 2021-09-25
  • 2019-02-25
  • 2021-11-11
  • 2021-09-25
相关资源
相似解决方案