Json 前端-添加新用途jqGrid?
我使用jqGrid添加新记录,但我不能将数据从网格放到json字符串中 运行时,返回代码: 错误状态:“不支持的媒体类型”。错误代码:415 我的代码是:Json 前端-添加新用途jqGrid?,json,jqgrid,frontend,Json,Jqgrid,Frontend,我使用jqGrid添加新记录,但我不能将数据从网格放到json字符串中 运行时,返回代码: 错误状态:“不支持的媒体类型”。错误代码:415 我的代码是: $(document).ready(function () { jQuery("#jQGridDemo").jqGrid({ url: 'http://192.168.1.59:8080/sunrise/api/v1/warehouse/getById/1', mtype: "GET", contentType: "a
$(document).ready(function () {
jQuery("#jQGridDemo").jqGrid({
url: 'http://192.168.1.59:8080/sunrise/api/v1/warehouse/getById/1',
mtype: "GET",
contentType: "application/json",
datatype: "json",
colNames: ['wareHouseID', 'name' , 'fullname' , 'company', 'address'],
colModel: [
{ name: 'wareHouseID', index: 'wareHouseID', width: 150,editable:false, editoptions:{readonly:true, size:10}, hidden:true},
{ name: 'name', index: 'name', width: 150,editable:true, editoptions:{size:30}},
{ name: 'fullname', index: 'fullname', width: 150,editable:true,editoptions:{size:30}},
{ name: 'company', index: 'company', width: 150,editable:true,editoptions:{size:30}},
{ name: 'address', index: 'address', width: 150,editable:true,editoptions:{size:30}}
],
rowNum: 10,
rowList:[10,20,30],
width: 1290,
sortname: 'wareHouseID',
sortorder:"desc",
height:235,
gridview: true,
viewrecords: true,
caption: "List User Details",
editurl:"http://192.168.1.59:8080/sunrise/api/v1/warehouse/update",
pager: "#jQGridDemoPager",
ajaxRowOptions : {
type :"POST",
contentType :"application/json",
dataType :"json"
},
serializeRowData: function(postData){
return JSON.stringify(postData);
}
});
$("#jQGridDemo").jqGrid('navGrid','#jQGridDemoPager',
{edit:true, add:true, del:false, search:true},
// Edit options
{
type:"PUT",
url:"http://192.168.1.59:8080/sunrise/api/v1/warehouse/update",
closeAfterEdit:true,
reloadAfterSubmit:true,
onclickSubmit: function(params, postData) {
return JSON.stringify(postData);
},
afterSubmit: function(response, postData) {
var res = jQuery.parseJSON(response.responseText);
return [true, "", res.d];
}
},
//Add option
{
type:"POST",
url:"http://192.168.1.59:8080/sunrise/api/v1/warehouse/new",
closeAfterAdd:true,reloadAfterSubmit:true,
onclickSubmit: function(params, postData) {
return JSON.stringify(postData);
},
afterSubmit: function(response, postData) {
var res = jQuery.parseJSON(response.responseText);
return [true, "", res.d];
}
}
);});
你能帮我找到一个问题并解决它吗?非常感谢。您的代码中有许多不清楚的部分。尽管如此,我猜想您遇到的主要问题如下:您使用
ajaxRowOptions
设置contentType
,并使用serializeRowData
将请求中的数据序列化为JSON。问题是:您使用表单编辑,但是ajaxRowOptions
和serializeRowData
仅在内联编辑的情况下使用
所以你应该使用
ajaxEditOptions:{contentType:“application/json”},
serializeEditData:函数(postData){
返回JSON.stringify(postData);
}
另外,还必须删除返回JSON.stringify(postData)的onclickSubmit
我希望它能解决这个问题。如果没有帮助,那么您应该首先写下您使用的jqGrid版本和jqGrid的分支(,或者@Zon:不客气!问题现在解决了吗?@Zon:不客气!如果问题解决了,您应该给出答案。