I am using the latest version of jqGrid: 3.6.4
This seems like a simple problem (or at least it did before I spent a few hours on it):
When the grid sends a request to the server (to a controller action), its content-type is always:
application/x-www-form-urlencoded; charset=UTF-8
and I would like it to be:
application/json; charset=utf-8
but I can find no way of setting the content-type (there is no contentType option as you would find on a $.ajax call for example).
So just to clarify, I am not asking how to set the content-type on a jQuery server request, but specifically using jqGrid, which does not provide an obvious option for doing this.
Thanks, Nigel.
Update:
Oleg’s response fixed solved it.
Here are the option settings for the grid:
jQuery("#ContactGridList").jqGrid({
url: '/ContactSelect/GridData/',
datatype: 'json',
ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
mtype: 'POST',
...
How you can find in the code of grid.base.js the
$.ajaxcall filling the grid contain looks like following:So you can use
ajaxGridOptionsoption of jqGrid to set or override any parameter of$.ajaxrequest. Because I use only JSON requests to my server, I set general setting ofcontentTypelikeThe
ajaxRowOptionsare used in grid.inlinedit.js for row editing. For the form edit there are other parameters, which I set also as global setting:How you can see my server is a RESTfull service (developed mainly in WFC and the rest in ASP.NET MVC). Because
$.jgrid.editis a setting for both “add” and “modify” items, I could not changemtype: "PUT"for “edit” only, so I do this in parameters ofnavGrid().The last ajax parameter which you could find also interesting to set is
ajaxSelectOptions. You can set it on the same way asajaxGridOptions. Parameters ofajaxSelectOptionsare useful if you usedataUrlparameter inside ofeditoptionsorsearchoptions. I use, for example,dataUrlinside ofcolModelfor defining columns of the typeedittype: 'select'. The possible values of select option will be loaded from server for inline or form editing or inside of search dialog. Because for such data loading are used ajax, there is correspondingajaxSelectOptionsoption.Best regards.