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

  7. #7
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    87
    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

      2  

    Default


    The missing piece of information here is that the 'headers' option is only valid when not doing a file upload.

  8. #8
    Sencha User
    Join Date
    Aug 2008
    Posts
    51
    Vote Rating
    7
    TonySteele is on a distinguished road

      2  

    Default


    '
    The missing piece of information here is that the 'headers' option is only valid when not doing a file upload' its still a missing bit of information! perhaps you should add it. I have just spent an hour trying to do this so that asp.net web.api will return json in response to a file upload.

  9. #9
    Sencha User
    Join Date
    Sep 2009
    Location
    London
    Posts
    54
    Vote Rating
    1
    harel is on a distinguished road

      0  

    Default This is pretty essential to allow setting headers for file uploads

    This is pretty essential to allow setting headers for file uploads


    Without headers in the file upload anything to do with header based authentication (api calls etc.) that require a file upload is just not possible...

  10. #10
    Sencha User
    Join Date
    Sep 2013
    Posts
    14
    Vote Rating
    1
    trenty is on a distinguished road

      0  

    Default


    [SOLVED]
    The issue described below seems solved for us.
    The Spring Security Doc says, that you can't set CSRF-Token as a request param for Ajax requests, so we did it in the HTTP header. But in case of normal form submits it works. (submits with file upload fields are normal form submits (no Ajax), as Condor said.)
    http://spring.io/blog/2013/08/21/spr...srf-protection

    Hi,

    we also need to set additional HTTP Headers (X-CSRF-TOKEN) for an file upload to work with our Spring Security configuration.

    Does anyone have a workaround or knows an approach how to fix it?


    Thank you very much!
    Last edited by trenty; 17 Oct 2013 at 12:59 AM. Reason: CSRF problem solved

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

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi