Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/372.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
Javascript 如何使用jqGrid将JSON发送到服务器?_Javascript_Jquery_Json_Post_Jqgrid - Fatal编程技术网

Javascript 如何使用jqGrid将JSON发送到服务器?

Javascript 如何使用jqGrid将JSON发送到服务器?,javascript,jquery,json,post,jqgrid,Javascript,Jquery,Json,Post,Jqgrid,[编辑](我等了3个小时才回答我的问题): 好吧,看来不是jqGrid组件出了故障,多亏了CodeDestroyer解决了这个问题 我测试了这段代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en

[编辑](我等了3个小时才回答我的问题): 好吧,看来不是jqGrid组件出了故障,多亏了CodeDestroyer解决了这个问题

我测试了这段代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>My First Grid</title>

<link rel="stylesheet" type="text/css" media="screen" href="./css/smoothness/jquery-ui-1.10.3.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="./css/ui.jqgrid.css" />

<style>
html, body {
    margin: 0;
    padding: 0;
    font-size: 100%;
}
</style>

<script src="./js/jquery-1.9.0.min.js" type="text/javascript"></script>
<script src="./js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="./js/jquery.jqGrid.min.js" type="text/javascript"></script>

<script type="text/javascript">


$(function () {
    $("#list").jqGrid({        
        url:'datas.php',
        datatype: "json",
        mtype: "GET",
        colNames: ["ID","Client", "Projet", "Tache", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"],
            colModel: [
                { name: "id_record", width: 55, hidden:false},
                { name: "client", width: 55, sortable:true},
                { name: "projet", width: 150, align: "right", sortable:true},
                { name: "tache", width: 150, align: "right", sortable:true},
                { name: "un", width: 20, align: "right", sortable:false, editable: true,  edittype: "select",editoptions: { value: "1:1; 0.5:0.5; 0.25:0.25" } },
                { name: "deux", width: 20, align: "right", sortable:false, editable: true,  edittype: "select",editoptions: { value: "1:1; 0.5:0.5; 0.25:0.25" }  },
                { name: "trois", width: 20, align: "right", sortable:false, editable: true,  edittype: "select",editoptions: { value: "1:1; 0.5:0.5; 0.25:0.25" }  },
                { name: "quatre", width: 20, align: "right", sortable:false, editable: true,  edittype: "select",editoptions: { value: "1:1; 0.5:0.5; 0.25:0.25" }  },
                { name: "cinq", width: 20, align: "right", sortable:false, editable: true,  edittype: "select",editoptions: { value: "1:1; 0.5:0.5; 0.25:0.25" }  },
                { name: "six", width: 20, align: "right", sortable:false, editable: true,  edittype: "select",editoptions: { value: "1:1; 0.5:0.5; 0.25:0.25" }  },
                { name: "sept", width: 20, align: "right", sortable:false, editable: true,  edittype: "select",editoptions: { value: "1:1; 0.5:0.5; 0.25:0.25" }  },
                { name: "huit", width: 20, align: "right", sortable:false, editable: true,  edittype: "select",editoptions: { value: "1:1; 0.5:0.5; 0.25:0.25" }  },
                { name: "neuf", width: 20, align: "right", sortable:false, editable: true,  edittype: "select",editoptions: { value: "1:1; 0.5:0.5; 0.25:0.25" }  },
                { name: "dix", width: 20, align: "right", sortable:false, editable: true,  edittype: "select",editoptions: { value: "1:1; 0.5:0.5; 0.25:0.25" }  },
                { name: "onze", width: 20, align: "right", sortable:false, editable: true,  edittype: "select",editoptions: { value: "1:1; 0.5:0.5; 0.25:0.25" }  },
                { name: "douze", width: 20, align: "right", sortable:false, editable: true,  edittype: "select",editoptions: { value: "1:1; 0.5:0.5; 0.25:0.25" }  },
                { name: "treize", width: 20, align: "right", sortable:false, editable: true,  edittype: "select",editoptions: { value: "1:1; 0.5:0.5; 0.25:0.25" }  },
                { name: "quatorze", width: 20, align: "right", sortable:false, editable: true,  edittype: "select",editoptions: { value: "1:1; 0.5:0.5; 0.25:0.25" }  },
                { name: "quinze", width: 20, align: "right", sortable:false, editable: true,  edittype: "select",editoptions: { value: "1:1; 0.5:0.5; 0.25:0.25" }  },
                { name: "seize", width: 20, align: "right", sortable:false, editable: true,  edittype: "select",editoptions: { value: "1:1; 0.5:0.5; 0.25:0.25" }  },
                { name: "dix-sept", width: 20, align: "right", sortable:false, editable: true,  edittype: "select",editoptions: { value: "1:1; 0.5:0.5; 0.25:0.25" }  },
                { name: "dix-huit", width: 20, align: "right", sortable:false, editable: true,  edittype: "select",editoptions: { value: "1:1; 0.5:0.5; 0.25:0.25" }  },
                { name: "dix-neuf", width: 20, align: "right", sortable:false, editable: true,  edittype: "select",editoptions: { value: "1:1; 0.5:0.5; 0.25:0.25" }  },
                { name: "vingt", width: 20, align: "right", sortable:false, editable: true,  edittype: "select",editoptions: { value: "1:1; 0.5:0.5; 0.25:0.25" }  },
                { name: "vingt-et-un", width: 20, align: "right", sortable:false, editable: true,  edittype: "select",editoptions: { value: "1:1; 0.5:0.5; 0.25:0.25" }  },
                { name: "vingt-deux", width: 20, align: "right", sortable:false, editable: true,  edittype: "select",editoptions: { value: "1:1; 0.5:0.5; 0.25:0.25" }  },
                { name: "vingt-trois", width: 20, align: "right", sortable:false, editable: true,  edittype: "select",editoptions: { value: "1:1; 0.5:0.5; 0.25:0.25" }  },
                { name: "vingt-quatre", width: 20, align: "right", sortable:false, editable: true,  edittype: "select",editoptions: { value: "1:1; 0.5:0.5; 0.25:0.25" }  },
                { name: "vingt-cinq", width: 20, align: "right", sortable:false, editable: true,  edittype: "select",editoptions: { value: "1:1; 0.5:0.5; 0.25:0.25" }  },
                { name: "vingt-six", width: 20, align: "right", sortable:false, editable: true,  edittype: "select",editoptions: { value: "1:1; 0.5:0.5; 0.25:0.25" }  },
                { name: "vingt-sept", width: 20, align: "right", sortable:false, editable: true,  edittype: "select",editoptions: { value: "1:1; 0.5:0.5; 0.25:0.25" }  },
                { name: "vingt-huit", width: 20, align: "right", sortable:false, editable: true,  edittype: "select",editoptions: { value: "1:1; 0.5:0.5; 0.25:0.25" }  },
                { name: "vingt-neuf", width: 20, align: "right", sortable:false, editable: true,  edittype: "select",editoptions: { value: "1:1; 0.5:0.5; 0.25:0.25" }  },
                { name: "trente", width: 20, align: "right", sortable:false, editable: true,  edittype: "select",editoptions: { value: "1:1; 0.5:0.5; 0.25:0.25" }  },
                { name: "trente-et-un", width: 20, align: "right", sortable:false, editable: true,  edittype: "select",editoptions: { value: "1:1; 0.5:0.5; 0.25:0.25" } },


            ],
        height: '100%',
        cellEdit: true,
        cellsubmit: 'remote',
        cellurl: "https://ort8m12c8ckf.runscope.net",
        pager: "#pager",
        rowNum: 10,
        rowList: [10, 20, 30],
        sortname: "id_record",
        sortorder: "asc",
        viewrecords: true,
        gridview: true,
        autoencode: true,
        caption: "My first grid",
        ajaxGridOptions: { contentType: "application/json"},
        ajaxCellOptions: { contentType: "application/json"},
        ajaxRowOptions: { contentType: "application/json"},
        beforeSubmitCell : function(rowid,celname,value,iRow,iCol) {

                selectedRowId = $('#list').jqGrid ('getGridParam', 'selrow');
                cellValue = $('#list').jqGrid('getCell', selectedRowId, 'id_record');   
                v = JSON.stringify({valeur: value,nom_cellule: celname,id_record: cellValue});
                send(v);
                return v; 
        },


       // serializeRowData: function (data) { alert("ok"); return JSON.stringify(data); },


    })
function send(datas){
        $.ajax({
            type: "POST",
            contentType: "application/json",
            url: 'https://ort8m12c8ckf.runscope.net',
            data: datas,
            dataType: "json"
        });
}
});
</script>

</head>
<body>
    <table id="list"><tr><td></td></tr></table> 
    <div id="pager"></div> 
    <input type="button" value="send"></input>

</body>
</html>

我的第一个网格
html,正文{
保证金:0;
填充:0;
字体大小:100%;
}
$(函数(){
$(“#列表”).jqGrid({
url:'datas.php',
数据类型:“json”,
mtype:“获取”,
colNames:[“ID”、“Client”、“Projet”、“Tache”、“1”、“2”、“3”、“4”、“5”、“6”、“7”、“8”、“9”、“10”、“11”、“12”、“13”、“14”、“15”、“16”、“17”、“18”、“19”、“20”、“21”、“22”、“23”、“24”、“25”、“26”、“27”、“28”、“29”、“30”、“31”],
colModel:[
{name:“id_记录”,宽度:55,隐藏:false},
{name:“client”,宽度:55,可排序:true},
{name:“projet”,宽度:150,对齐:“right”,可排序:true},
{name:“tache”,宽度:150,对齐:“right”,可排序:true},
{name:“un”,width:20,align:“right”,sortable:false,edit:true,edittype:“select”,editoptions:{value:“1:1;0.5:0.5;0.25:0.25”},
{name:“deux”,width:20,align:“right”,sortable:false,edittype:true,edittype:“select”,editoptions:{value:“1:1;0.5:0.5;0.25:0.25”},
{name:“trois”,width:20,align:“right”,sortable:false,edittype:true,edittype:“select”,editoptions:{value:“1:1;0.5:0.5;0.25:0.25”},
{name:“quatre”,width:20,align:“right”,sortable:false,edittype:true,edittype:“select”,editoptions:{value:“1:1;0.5:0.5;0.25:0.25”},
{name:“cinq”,width:20,align:“right”,sortable:false,edittype:true,edittype:“select”,editoptions:{value:“1:1;0.5:0.5;0.25:0.25”},
{name:“six”,width:20,align:“right”,sortable:false,edittype:true,edittype:“select”,editoptions:{value:“1:1;0.5:0.5;0.25:0.25”},
{name:“sept”,width:20,align:“right”,sortable:false,edittype:true,edittype:“select”,editoptions:{value:“1:1;0.5:0.5;0.25:0.25”},
{name:“huit”,width:20,align:“right”,sortable:false,edittype:true,edittype:“select”,editoptions:{value:“1:1;0.5:0.5;0.25:0.25”},
{name:“neuf”,width:20,align:“right”,sortable:false,edittype:true,edittype:“select”,editoptions:{value:“1:1;0.5:0.5;0.25:0.25”},
{name:“dix”,width:20,align:“right”,sortable:false,edittype:true,edittype:“select”,editoptions:{value:“1:1;0.5:0.5;0.25:0.25”},
{name:“onze”,width:20,align:“right”,sortable:false,edittype:true,edittype:“select”,editoptions:{value:“1:1;0.5:0.5;0.25:0.25”},
{name:“douze”,width:20,align:“right”,sortable:false,edittype:true,edittype:“select”,editoptions:{value:“1:1;0.5:0.5;0.25:0.25”},
{name:“treize”,width:20,align:“right”,sortable:false,edittype:true,edittype:“select”,editoptions:{value:“1:1;0.5:0.5;0.25:0.25”},
{name:“quatorze”,width:20,align:“right”,sortable:false,edittype:true,edittype:“select”,editoptions:{value:“1:1;0.5:0.5;0.25:0.25”},
{name:“quinze”,width:20,align:“right”,sortable:false,edittype:true,edittype:“select”,editoptions:{value:“1:1;0.5:0.5;0.25:0.25”},
{名称:“抓住”,宽度:20,对齐:“右”,可排序:false,可编辑:true,edittype:“选择”,editoptions:{值:“1:1;0.5:0.5;0.25:0.25”},
{name:“dix sept”,width:20,align:“right”,sortable:false,edittype:true,edittype:“select”,editoptions:{value:“1:1;0.5:0.5;0.25:0.25”},
{name:“dix huit”,width:20,align:“right”,sortable:false,edit:true,edittype:“select”,editoptions:{value:“1:1;0.5:0.5;0.25:0.25”},
{name:“dix neuf”,width:20,align:“right”,sortable:false,edit:true,edittype:“select”,editoptions:{value:“1:1;0.5:0.5;0.25:0.25”},
{name:“vingt”,width:20,align:“right”,sortable:false,edittype:true,edittype:“select”,editoptions:{value:“1:1;0.5:0.5;0.25:0.25”},
{name:“vingtet un”,width:20,align:“right”,sortable:false,edit:true,edittype:“select”,editoptions:{value:“1:1;0.5:0.5;0.25:0.25”},
{name:“vingtdeux”,宽度:20,对齐:“right”,可排序:false,可编辑:true,edittype:“select”,editoptions:{value:“1:1;0.5:0.5;0.25:0.25”},
{name:“vingtrois”,width:20,align:“right”,sortable:false,edit:true,edittype:“select”,editoptions:{value:“1:1;0.5:0.5;0.25:0.25”},
{name:“vingtquare”,宽度:20,对齐:“right”,可排序:false,可编辑:true,edittype:“select”,editoptions:{value:“1:1;0.5:0.5;0.25:0.25”},
{name:“vingtcinq”,width:20,align:“right”,sortable:false,edit:true,edittype:“select”,editoptions:{value:“1:1;0.5:0.5;0.25:0.25”},
{name:“vingtsix”,width:20,align:“right”,sortable:false,edittype:true,edittype:“select”,editoptions:{value:“1:1;0.5:0.5;0.25:0.25”},
{name:“vingtsept”,width:20,align:“right”,sortable:false,edittype:true,edittype:“select”,editoptions:{value:“1:1;0.5:0.5;0.25:0.25”},
{name:“vingthuit”,width:20,align:“right”,sortable:false,edit:true,edittype:“select”,editoptions:{value:“1:1;0.5:0.5;0.25:0.25”},
{name:“vingtneuf”,宽度:20,对齐:“right”,可排序:false,可编辑:true,edittype:“select”,editoptions:{value:“1:1;0.5:0.5;0.25:0.25”},
{名称:“trente”,宽度:20,对齐:“right”,可排序:false,可编辑:true,edittype:“select”,editoptions:{值:“1:1;0.5:0.5;
   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>My First Grid</title>

<link rel="stylesheet" type="text/css" media="screen" href="./css/smoothness/jquery-ui-1.10.3.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="./css/ui.jqgrid.css" />

<style>
html, body {
    margin: 0;
    padding: 0;
    font-size: 100%;
}
</style>

<script src="./js/jquery-1.9.0.min.js" type="text/javascript"></script>
<script src="./js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="./js/jquery.jqGrid.min.js" type="text/javascript"></script>

<script type="text/javascript">


$(function () {
    $("#list").jqGrid({        
        url:'datas.php',
        datatype: "json",
        mtype: "GET",
        colNames: ["ID","Client", "Projet", "Tache", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"],
            colModel: [
                { name: "id_record", width: 55, hidden:false},
                { name: "client", width: 55, sortable:true},
                { name: "projet", width: 150, align: "right", sortable:true},
                { name: "tache", width: 150, align: "right", sortable:true},
                { name: "un", width: 20, align: "right", sortable:false, editable: true, key: false },
                { name: "deux", width: 20, align: "right", sortable:false, editable: true, key: false },
                { name: "trois", width: 20, align: "right", sortable:false, editable: true, key: false },
                { name: "quatre", width: 20, align: "right", sortable:false, editable: true, key: false },
                { name: "cinq", width: 20, align: "right", sortable:false, editable: true, key: false },
                { name: "six", width: 20, align: "right", sortable:false, editable: true, key: false },
                { name: "sept", width: 20, align: "right", sortable:false, editable: true, key: false },
                { name: "huit", width: 20, align: "right", sortable:false, editable: true, key: false },
                { name: "neuf", width: 20, align: "right", sortable:false, editable: true, key: false },
                { name: "dix", width: 20, align: "right", sortable:false, editable: true, key: false },
                { name: "onze", width: 20, align: "right", sortable:false, editable: true, key: false },
                { name: "douze", width: 20, align: "right", sortable:false, editable: true, key: false },
                { name: "treize", width: 20, align: "right", sortable:false, editable: true, key: false },
                { name: "quatorze", width: 20, align: "right", sortable:false, editable: true, key: false },
                { name: "quinze", width: 20, align: "right", sortable:false, editable: true, key: false },
                { name: "seize", width: 20, align: "right", sortable:false, editable: true, key: false },
                { name: "dix-sept", width: 20, align: "right", sortable:false, editable: true, key: false },
                { name: "dix-huit", width: 20, align: "right", sortable:false, editable: true, key: false },
                { name: "dix-neuf", width: 20, align: "right", sortable:false, editable: true, key: false },
                { name: "vingt", width: 20, align: "right", sortable:false, editable: true, key: false },
                { name: "vingt-et-un", width: 20, align: "right", sortable:false, editable: true, key: false },
                { name: "vingt-deux", width: 20, align: "right", sortable:false, editable: true, key: false },
                { name: "vingt-trois", width: 20, align: "right", sortable:false, editable: true, key: false },
                { name: "vingt-quatre", width: 20, align: "right", sortable:false, editable: true, key: false },
                { name: "vingt-cinq", width: 20, align: "right", sortable:false, editable: true, key: false },
                { name: "vingt-six", width: 20, align: "right", sortable:false, editable: true, key: false },
                { name: "vingt-sept", width: 20, align: "right", sortable:false, editable: true, key: false },
                { name: "vingt-huit", width: 20, align: "right", sortable:false, editable: true, key: false },
                { name: "vingt-neuf", width: 20, align: "right", sortable:false, editable: true, key: false },
                { name: "trente", width: 20, align: "right", sortable:false, editable: true, key: false },
                { name: "trente-et-un", width: 20, align: "right", sortable:false, editable: true, key: false},


            ],
        height: '100%',
        cellEdit: true,
        cellsubmit: 'remote',
        cellurl: "https://ort8m12c8ckf.runscope.net",
        pager: "#pager",
        rowNum: 10,
        rowList: [10, 20, 30],
        sortname: "id_record",
        sortorder: "asc",
        viewrecords: true,
        gridview: true,
        autoencode: true,
        caption: "my first grid
        gridview: true,

        beforeSubmitCell : function(rowid,celname,value,iRow,iCol) {

                selectedRowId = $('#list').jqGrid ('getGridParam', 'selrow');
                cellValue = $('#list').jqGrid('getCell', selectedRowId, 'id_record');

                return {valeur:value,nom_cellule:celname,id_record:cellValue}; 
        }

    })
});
</script>

</head>
<body>

    <table id="list"><tr><td></td></tr></table> 
    <div id="pager"></div> 
</body>
</html>
rowid = selectedRowId
cellValue = value
beforeSubmitCell : function(rowid,celname,value,iRow,iCol) {

            selectedRowId = $('#list').jqGrid ('getGridParam', 'selrow');
            cellValue = $('#list').jqGrid('getCell', selectedRowId, 'id_record');

            return JSON.stringify({valeur: value,nom_cellule: celname,id_record: cellValue});
    }