json - Frontend - Add new use jqGrid? -
i use jqgrid add new record, can't put data grid json string.
when run, return code:
error status: 'unsupported media type'. error code: 415
and code:
$(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]; } } );});
could me find problem , how fix it? tks much.
there many unclear parts in code. nevertheless guess main problem have following: use ajaxrowoptions
set contenttype
, use serializerowdata
serialize data request json. problem is: use form editing, ajaxrowoptions
, serializerowdata
used in case of inline editing.
so should use
ajaxeditoptions: { contenttype :"application/json" }, serializeeditdata: function (postdata) { return json.stringify(postdata); }
you have remove onclicksubmit
returns json.stringify(postdata)
additionally.
i hope should solve problem. if not should write first of version of jqgrid use , fork of jqgrid use (free jqgrid, guriddo jqgrid js or old jqgrid in version <= 4.7). should write additionally more information server reruns error "'unsupported media type'. error code: 415".
Comments
Post a Comment