Reputation: 3371
I am using the saveRow function in inline_editing in jqGrid, the default Content-Type is "application/x-www-form-urlencoded; charset=UTF-8" with the following
saveparameters = { "successfunc" : null, "url" : myUrl, "extraparam" : {}, "aftersavefunc" : null, "errorfunc": null, "afterrestorefunc" : null, "restoreAfterError" : true, "mtype" : "POST" } jQuery("#grid_id").jqGrid('saveRow',rowid, saveparameters);
I want to overwrite the Content-Type to "application/json; charset=utf-8", so I can have the successfunc like
successfunc : function(response){ //parse the json response }
Is this possible and how to overwrite it? Thanks
Upvotes: 1
Views: 287
Reputation: 134157
No, unfortunately the grid does not allow you to specify the contentType
option in this particular calls to jQuery.ajax
- you can see it yourself in the source code to grid.inlinedit.js
. Thus it uses the default content type as you noted in your question.
But maybe that's OK. It seems like what you really want is to receive JSON data, in which case the format of the data sent to the server does not matter. The reponse format is controlled by the dataType
option, which also cannot be specified in the jqGrid API. However, it is inferred based upon the MIME type from your server's response:
Default: Intelligent Guess (xml, json, script, or html) The type of data that you're expecting back from the server. If none is specified, jQuery will try to infer it based on the MIME type of the response (an XML MIME type will yield XML, in 1.4 JSON will yield a JavaScript object, in 1.4 script will execute the script, and anything else will be returned as a string). The available types (and the result passed as the first argument to your success callback) are:
So just make sure you set the MIME type in your response to application/json; charset=utf-8
and you should be good.
Upvotes: 0