代码之家  ›  专栏  ›  技术社区  ›  Felix

加载jgrid之前的Ajax调用

  •  0
  • Felix  · 技术社区  · 16 年前

    我需要从php脚本预加载一些值,我使用$.post调用(jquery),如下所示:

    ...    
    var grade, section,from,until,user;
    
    
            function loadData(){
                $.post('procstring.php', {data: window.location.hash},
                       function(result){
                        grade = result.grade;
                        section = result.section;
                        from = result.from;
                        until = result.until;
                        user = result.user;
                        },
                'json');
            }
    

    我需要这个值来呈现这样的jqgrid

    $("#list").jqGrid({
    
                url: 'report.php?g=' + grade + '&s=' + section + '&f=' + from + '&u='+ until + '&u=' + user + '&report=1&searchString=null&searchField=null&searchOper=null',
                datatype: 'json',
                mtype: 'GET',
    …
    

    所以我先调用loadData $("#list").jqGrid({…

    我尝试过像beforeRequest和loadBeforeSend这样的jgrid事件,但没有效果。

    有什么建议吗?。谢谢。

    1 回复  |  直到 16 年前
        1
  •  0
  •   Darin Dimitrov    16 年前

    因为AJAX是异步的。你需要把 $("#list").jqGrid({... 在成功回调中:

    // No need to define the variables outside
    $.post('procstring.php', { data: window.location.hash },
        function(result)
            var grade = result.grade;
            var section = result.section;
            var from = result.from;
            var until = result.until;
            var user = result.user;
    
            $("#list").jqGrid({...
    },
    'json');
    
    推荐文章