Hybrid View

  1. #1
    Sencha User
    Join Date
    Nov 2010
    Posts
    85
    Vote Rating
    1
    KallDrexx is on a distinguished road

      0  

    Default How can I add headers to getForm.Submit() calls?

    How can I add headers to getForm.Submit() calls?


    I have come up with an issue that certain headers are not being sent when I call getForm.submit(). For example, the "X-Requested-With" header is not being sent, which is causing Asp.Net to not detect the form submission request as an Ajax request, which I need it to do for various reasons (e.g. send errors via Json and not error 500 Html pages).

    I tried adding "headers: { 'X-Requested-With' : 'XMLHttpRequest' }," to my submit() call, but this did not work. I then tried to modify the default headers with "Ext.Ajax.defaultHeaders = { 'My-Test': 'Test worked' };". When I did this, all my requests are correctly sending the 'My-Test' header except for form submissions.

    Does anyone know how I can correctly add the X-Requested-With header to form submission calls?

  2. #2
    Sencha User
    Join Date
    Nov 2010
    Posts
    85
    Vote Rating
    1
    KallDrexx is on a distinguished road

      0  

    Default


    So is this not possible? Is this a bug or a design decision?

  3. #3
    Sencha User darthwes's Avatar
    Join Date
    Mar 2010
    Posts
    633
    Vote Rating
    -11
    darthwes can only hope to improve

      0  

    Default


    MMM, Why don't you just do an ajax request then?

    Code:
    var frmVals = this.getForm().getValues();
    Ext.Ajax.request({
      params: frmVals,
      url: this.url,
      ...
    });
    not so bad, right?
    Wes

  4. #4
    Sencha User
    Join Date
    Nov 2010
    Posts
    85
    Vote Rating
    1
    KallDrexx is on a distinguished road

      1  

    Default


    How do I upload a file with an Ajax request?

  5. #5
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    96
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    You can't upload files with an Ext.Ajax request.

    You have to use a form submit, which doesn't support setting headers.

  6. #6
    Sencha Premium Member
    Join Date
    May 2010
    Posts
    28
    Vote Rating
    0
    donp is on a distinguished road

      0  

    Default


    But, the form object docs say that it does support headers.


    doAction( String/Object actionName, [COLOR=#444444! important][Object options] ) : BasicForm
    Performs a predefined action (Ext.form.Action.Submit or Ext.form.Action.Load) or a custom extension of Ext.form.Action to perform application-specific processing.Parameters:
    • actionName : String/ObjectThe name of the predefined action type, or instance of Ext.form.Action to perform.
    • options : Object(optional) The options to pass to the Ext.form.Action. All of the config options listed below are supported by both the submit and load actions unless otherwise noted (custom actions could also accept other config options):
      • url : StringThe url for the action (defaults to the form's url.)
      • method : StringThe form method to use (defaults to the form's method, or POST if not defined)
      • params : String/ObjectThe params to pass (defaults to the form's baseParams, or none if not defined)
        Parameters are encoded as standard HTTP parameters using Ext.urlEncode.
      • headers : ObjectRequest headers to set for the action (defaults to the form's default headers)


    [/COLOR]
    If we are using JSON, how are we supposed to set the Content-type header to be applicatoin/json, when the form is submitted? If we can't do this, then we can't use the form's submit action.

    Don P.

Similar Threads

  1. Pass field how parameter from getForm().submit({
    By chuvinha in forum Ext 3.x: Help & Discussion
    Replies: 5
    Last Post: 4 Jan 2011, 10:36 AM
  2. Doubt arquivoForm.getForm().submit({
    By chuvinha in forum Ext 3.x: Help & Discussion
    Replies: 0
    Last Post: 4 Jan 2011, 10:27 AM
  3. Unable to submit from combo after myForm.getForm().setValues();
    By cshamis in forum Ext 3.x: Help & Discussion
    Replies: 2
    Last Post: 14 Sep 2010, 12:49 AM
  4. Can't submit my form (win.getForm() is not a function)
    By michiel in forum Ext 2.x: Help & Discussion
    Replies: 4
    Last Post: 23 Jun 2008, 7:16 AM

Thread Participants: 6