如何使用post ajax请求在jqgrid中显示数据?

时间:2014-08-26 08:26:24

标签: php jquery ajax

我似乎找不到使用post ajax

显示数据的方法

当我在变量中预定义json数据时,它会读取。但是当我使用post ajax从服务器检索数据并在jqgrid中显示它似乎无法工作。

继承我的代码:

  var grid_selector = "#grid-table";
    var pager_selector = "#grid-pager";

    $.post(pathFile+"loadPaymentDetails",{id:id,action:'loadPaymentDetails'},function(response,status){
        var result = [{"0":"3","id":"3","1":"82","payment_id":"82","2":"0000-00-00 00:00:00","payment_issue_date":"0000-00-00 00:00:00","3":"100","payment_ref_number":"100","4":"0","payment_mode_id":"0","5":"121212","payment_amount":"121212","6":"","payment_description":""}];
        if (status == "success") {

        var grid_data =  response
        $(grid_selector).jqGrid({
                data: grid_data,
                datatype: "local",
                height: 250,
                colNames:[' ', 'payment_issue_date','payment_ref_number'],
                colModel:[
                    {name:'myac',index:'', width:80, fixed:true, sortable:false, resize:false

                    },
                    {name:'payment_issue_date',index:'payment_issue_date', width:60, sorttype:"int", editable: true},
                    {name:'payment_ref_number',index:'payment_ref_number',width:90, editable:true, sorttype:"date"},

                ], 

                viewrecords : true,
                rowNum:10,
                rowList:[10,20,30],
                pager : pager_selector,
                altRows: true,
                //toppager: true,

                multiselect: true,
                //multikey: "ctrlKey",
                multiboxonly: true,



                //editurl: $path_base+"/dummy.html",//nothing is saved
                caption: "jqGrid with inline editing",


                autowidth: true

            });
        }
    })   

我可以使用结果变量在jqgrid中显示数据,但是当我使用来自ajax调用的响应时,虽然输出相同,但它似乎不起作用。

1 个答案:

答案 0 :(得分:1)

我用:

$("#tab_vsebine").jqGrid({ mtype: 'POST', url:<your ajax url call>, postData: {param1:value, param2:value,...}, datatype: "json", colNames:[...], colModel:[...], . . . });