FormPanel and "Bad request" errors

  1. #1

    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.
    <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?

  2. #2

    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?
  3. #3

    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 ...

Similar Threads

  1. Replies: 5
    Last Post: Dec 03, 2012, 4:17 AM
  2. Replies: 0
    Last Post: Nov 17, 2011, 10:53 AM
  3. [CLOSED] Errors regarding TreePanel
    By jesperhp in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Nov 16, 2011, 8:30 AM
  4. Publish Errors
    By Juls in forum 1.x Help
    Replies: 2
    Last Post: Jun 16, 2009, 2:54 PM
  5. Consistently getting errors using Coolite
    By r_honey in forum 1.x Help
    Replies: 12
    Last Post: Dec 14, 2008, 6:23 AM

Posting Permissions