【发布时间】:2011-05-17 12:50:58
【问题描述】:
我正在尝试使用 JSON 数据设置 jqgrid。
我的问题是我的服务返回的数据是 xml 格式。
我在 firebug 中跟踪了网格发送的请求,它是这样说的:
Request Headers
Host localhost
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
Accept application/json, text/javascript, */*; q=0.01
Accept-Language en-gb,en;q=0.5
Accept-Encoding gzip, deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 115
Connection keep-alive
Content-Type application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With XMLHttpRequest
Referer http://localhost/sample/sampleUserSearchPage.htm
Content-Length 60
Cookie ASP.NET_SessionId=yfx42t45b0nidn45yztqzsun
注意 Content-Type 字段。
我将此与我正在发出的另一个 jQuery.ajax 请求进行了比较,我注意到唯一的区别在于 Content-Type 字段。在另一个请求(返回 json)中,Content-Type 是 application/json; charset=UTF-8;
我认为这是问题所在,但我在 jqgrid 文档上找不到如何更改它。
附件是我的jQuery代码:
$("#grid").jqGrid({
url: 'SampleScriptService.asmx/GetGridData',
datatype: "json",
mtype: "POST",
jsonReader : { root: "rows" },
colNames: ['Username', 'Full Name', 'Monitor?', 'Schedule?', 'Reports?', 'Administrator?', 'Password'],
colModel: [
{ name: 'username', key: true, index: 'id', jsonmap: 'Username' },
{ name: 'fullname', index: 'invdate', width: 90 , jsonmap: 'FullName' },
{ name: 'ismonitor', index: 'name', width: 100, jsonmap: 'IsMonitor' },
{ name: 'isschedule', index: 'amount', width: 80, jsonmap: 'IsSchedule' },
{ name: 'isreports', index: 'tax', width: 80, jsonmap: 'IsReports' },
{ name: 'isadministrator', index: 'total', width: 80, jsonmap: 'IsAdministrator' },
{ name: 'password', index: 'note', width: 150, jsonmap: 'Password' }
],
rowNum: 10,
viewrecords: true,
caption: "Simple data manipulation",
});
和web服务方法:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public GridData GetGridData(int page, int rows, /*string sixd,*/ string sord)
{
var arr= new UsersController().SearchUsers("", 10, 0).ToArray(); //this returns an array of User objects.
GridData retVal = new GridData() { page = 1, records = 6, total = 34, rows = arr };
return retVal;
}
【问题讨论】:
标签: jquery jquery-plugins jqgrid