我是jqGrid的新手。但是,成功地使用jqGrid主要藉助Oleg的答案來開發應用程序。 我加載一個jqGrid的基礎上下拉選擇。數據是從Web服務(asmx)文件返回的。 的代碼是一些這樣的事jqGrid內容類型在表單編輯
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");
}
}
},
......
螢火蟲顯示以下帖子標題
響應頭
......
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
正如處爲建議tackoverflow我用
ajaxEditOptions: { contentType: 'application/json; charset=utf-8', dataType: 'json' } ,
我想即使在
jQuery.extend(jQuery.jgrid.edit, {
ajaxEditOptions: { contentType: 'application/json; charset=utf-8', dataType: 'json' },
...
});
使用ajaxEditoptions
但是沒有在Content-Type
沒有變化。 因此,我總是從服務器獲取更新的XML響應。從服務器的輸出是
<string xmlns="http://tempuri.org/">Data Saved</string>
我無法修復,MIME類型爲JSON。請幫忙。
謝謝,不用你的答案和代碼我無法完成它。順便說一句,我總是做一個谷歌,像JQGrid奧列格。剛纔可以找出問題。在我的代碼中有一個navGrid方法,它是.jqGrid('navGrid','#pager',{edit:true,add:false,del:false,refresh:true,search:true}, { closeAfterEdit:false }); });我覺得這是覆蓋寫入ajaxEditOptions的jQuery.jgrid.edit。因爲當我將ajaxEditOptions放入navGrid方法的時候,它正在發送一個正確的啞劇。你怎麼看? –
Dibs
您可以使用'.extend($ .jgrid.edit,{ajaxEditOptions:{contentType:「application/json」}});''或者您可以使用'.jqGrid('navGrid','#pager',{edit :true,add:false,del:false,refresh:true,search:true},{closeAfterEdit:false,ajaxEditOptions:{contentType:「application/json」}});'。 **這兩種方式應該工作**。如果它不起作用,你可以發佈我的網址與演示重現問題的演示。請在演示中使用'jquery.jqGrid.src.js'。 – Oleg
他們都應該工作。但是,如果同時使用(無意)與navGrid具有.jqGrid('navGrid','#pager',{edit:true,add:false,del:false,refresh:true,search:true},{closeAfterEdit :false和$ .extend有一個AjaxEditOptions。在我的情況下,它發送一個MIME類型的text/xml,當我刪除$ .extend中的ajaxEditOptions,並將其放入navGid方法時,它開始發送正確的MIME,再次感謝Oleg。 – Dibs