JQuery JQGrid breaks when contentType = application / json?
I had to use $ .ajaxSetup () to globally change contentType to application / json
$.ajaxSetup({
contentType: "application/json; charset=utf-8"
});
(see this question why I had to use application / json ASPNET MVC - Why ModelState.IsValid false "Field x is required" when this field has a value? )
But this breaks jquery jqrid with this error:
Invalid JSON primitive: _search
The POST data it is trying to send is:
_search=false&nd=1274042681880&rows=20&page=1&sidx=&sord=asc
Which one is not in json format, so of course it fails. Is there anyway to tell jqrid which content type to use?
I have searched on the jqrid wiki but there really isn't a lot of documentation.
http://www.trirand.com/jqgridwiki/doku.php?do=search&id=contenttype&fulltext=Search
a source to share
First of all, I can post my old answer to you on Setting the Content Type of Requests Made by jQuery jqGrid . It shows what an ajax request looks like inside a jqGrid. Thus, you should use the ajaxGridOptions
jqGrid parameter instead of overwriting the global settings in relation $.ajaxSetup
.
Also, in the same answer, you can see how you can use serializeGridData
the jqGrid parameter to create a custom serialization. Q How do I create a JSON object to send to an AJAX WebService? you can read what the JSON encoding of the parameters looks like.
If you have any problems using serializeGridData
and ajaxGridOptions
, you should include in your question the code snippet using jqGrid and the prototype of your web service server method you are using.
a source to share