FormPanel and "Bad request" errors
I have the following Coolite controls and markup in my APSX page - I've left out the entire page markup as it's not relevant.
The page's purpose is to call a remote service method which returns a JSON-serialized object back to the page - this is achieved by the ExtJS call in the DocumentReady handler as below.
Code:
<ext:ScriptManagerProxy runat="server" ID="ScriptManagerProxyMain">
<Listeners>
<DocumentReady Handler="if (globalPersonId) {
var request = {};
request.personId = globalPersonId;
alert('Request='+Ext.util.JSON.encode(request));
#{PersonForm}.load({params: Ext.util.JSON.encode(request)});
}
" />
</Listeners>
</ext:ScriptManagerProxy>
.
.
.
<ext:FormPanel
ID="PersonForm" runat="server" Title="Candidate details"
BodyStyle="padding:5px;"
Method="POST"
AutoWidth="true"
AutoScroll="true"
Border="false"
Url="~/Services/PersonService.svc/AjaxEndpoint/GetPerson"
>
.
.
.
.
</ext:FormPanel>
The problem is, when I snoop the HTTP traffic between client and server, the call to load the form causes the following ASP.NET error - The server encountered an error processing the request. The exception message is 'The incoming message has an unexpected message format 'Raw'. The expected message formats for the operation are 'Xml', 'Json'.
From examining the request header, I can see that the content-type is application/x-www-form-urlencoded; charset=UTF-8 whereas it should be application/json.
My question is, how do I set up the request so that it's sent as JSON and not RAW?
RE: FormPanel and "Bad request" errors
I guess the short version of my question is, how do I get the FormPanel.load to post the request as content-type "application/json" rather than the default
"application/x-www-form-urlencoded"
Please don't tell me to use a Store to load the form fields, otherwise, where's the point of the form load method?
RE: FormPanel and "Bad request" errors
Solved it using a call to:
Ext.lib.Ajax.defaultPostHeader = 'application/json'
in the documentready handler.
Self-support at it's finest ...