我是 jqGrid 的新手。但是,主要是在 Oleg 的回答的帮助下,成功地使用 jqGrid 开发了一个应用程序。我根据下拉列表的选择加载了一个 jqGrid。数据从 Web 服务 (asmx) 文件返回。代码是这样的
jQuery("#list").jqGrid({
url: '<%= ResolveClientUrl("OfficeData.asmx/GetSCFS_RO") %>',
editurl: '<%= ResolveClientUrl("OfficeData.asmx/SaveFPSUpdates") %>',
datatype: "json",
mtype: 'POST',
ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
ajaxEditOptions: { contentType: 'application/json; charset=utf-8', dataType: 'json' },
serializeGridData: function (postData) {
// return null;
if (postData.OfficeId === undefined) { postData.OfficeId = 0; }
else {
postData.OfficeId = officeId;
}
return JSON.stringify(postData);
},
jsonReader: { repeatitems: false, root: "d.rows", page: "d.page",
total: "d.total", records: "d.records" },
colNames: ['FPSCode', 'Owner Name ', 'Licese_No', 'ShopAddress', 'Village',
'License Valid From', 'Valid To','FPS Type','WholeSalerName', 'Mobile'],
colModel: [{ name: 'FPSCode', index: 'FPSCode', width: 60, align: 'left',
editable:true, editrules:{required:true},
editoptions:{
dataInit: function(element) {
$(element).attr("readonly", "readonly");
}
}
},
......
Firebug 显示以下 Post 标头
响应标头
......
Content-Type application/json; charset=utf-8
Date Tue, 20 Nov 2012 14:20:34 GMT
Server ASP.NET Development Server/10.0.0.0
X-AspNet-Version 4.0.30319
请求标头
Accept application/json, text/javascript, */*; q=0.01
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Cache-Control no-cache
Connection keep-alive
Content-Length 105
..........
正如预期的那样,我得到的响应是 JSON 对象。
但是表单提交总是发送Content-Type
为application/x-www-form-urlencoded; charset=UTF-8
响应标头
Cache-Control private, max-age=0
Connection Close
Content-Length 95
Content-Type text/xml; charset=utf-8
Date Tue, 20 Nov 2012 14:20:46 GMT
Server ASP.NET Development Server/10.0.0.0
请求标头
Accept */*
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Cache-Control no-cache
Connection keep-alive
Content-Length 254
Content-Type application/x-www-form-urlencoded; charset=UTF-8
Cookie ASP.NET_SessionId=utts2wlhdto4xhae34fzqkt4
Host localhost:18017
Pragma no-cache
Referer Account/FPSUpdate.aspx
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20100101 Firefox/16.0
X-Requested-With XMLHttpRequest
X-AspNet-Version 4.0.30319
正如我在 Stackoverflow 上所建议的那样
ajaxEditOptions: { contentType: 'application/json; charset=utf-8', dataType: 'json' } ,
ajaxEditoptions
我什至尝试使用
jQuery.extend(jQuery.jgrid.edit, {
ajaxEditOptions: { contentType: 'application/json; charset=utf-8', dataType: 'json' },
...
});
但是 . 中没有任何变化Content-Type
。因此,我总是从服务器收到更新的 XML 响应。服务器的输出是
<string xmlns="http://tempuri.org/">Data Saved</string>
我无法将 Mime 类型修复为 JSON。请帮忙。