Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery Jqgrid未使用新数据更新_Jquery_Json_Asp.net Mvc_Jqgrid - Fatal编程技术网

Jquery Jqgrid未使用新数据更新

Jquery Jqgrid未使用新数据更新,jquery,json,asp.net-mvc,jqgrid,Jquery,Json,Asp.net Mvc,Jqgrid,我有jqgrid实现,无法在其中加载数据。我附上代码,请让我知道。我正在从控制器成功检索数据,无法用新数据重新加载jqgrid $("#btn1").on("click", function() { alert(j + " " + k); var d = { 'firstField': i, 'secondField': j, 'thirdField': k } $.ajax({ type: 'post', url: '/TodoList/

我有jqgrid实现,无法在其中加载数据。我附上代码,请让我知道。我正在从控制器成功检索数据,无法用新数据重新加载jqgrid

$("#btn1").on("click", function() {
    alert(j + " " + k);
    var d = { 'firstField': i, 'secondField': j, 'thirdField': k }
    $.ajax({
        type: 'post',
        url: '/TodoList/searchdata',
        traditional: true,
        dataType: "json",
        data: d,
        success: function(data) {
            callme(data);
        }
    })

});

function callme(newone1) {
    var my = JSON.stringify(newone1.rows);
    alert(my);
    /*
        Json showing in this alert is 
        [{"accntname":"BSNL","BU":"BCS","salesop":50000,"isdormant":true},
         {"accntname":"TATA","BU":"HPSD","salesop":50000,"isdormant":false}]
        */

    $grid.jqGrid('clearGridData');
    $grid.jqGrid('setGridParam', {
        datatype: 'local',
        data: my
    }).trigger("reloadGrid");
}
我正在尝试用新数据重新加载的Jqgrid:

var mydata = [];
$grid.jqGrid({
    datatype: "local",
    data: mydata,
    colModel: [
        { name: "accntname", align: "center", title: false, width: 400, resizable: false, sortable: false },
        { name: "BU", width: 125 },
        { name: "salesop", align: "center", width: 125, sorttype: "date" },
        { name: "isdormant", align: "center", width: 125, sorttype: "date" }
    ],
    caption: "Viz Test",
    pager: '#pager',
    search: true,
    multiselect: true
});

您正在接收的数据是json,这是Jqgrid所期望的,因此您不应该对数据进行字符串化。将函数修改为

function callme(newone1) {
    $grid.jqGrid('clearGridData');
    $grid.jqGrid('setGridParam', {
      datatype: 'local',
      data: newone1.rows // modify this
    }).trigger("reloadGrid");
}

旁注:<代码>传统:Trime< /Cord>Ajax选项不需要(您不向控制器发送数组)

,那么也许您应该考虑接受答案。