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

+2


a source to share


2 answers


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.

+3


a source


When setting up jqGrid or its datasource, set dataType

to JSON ( "json"

) like:

$("#myTable").jqGrid ({
  //other options...
  dataType : 'json'
});

      



You can also see a sample code project .

0


a source







All Articles