-
19 Jan 2011 9:43 AM #1
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?
-
21 Jan 2011 7:54 AM #2
So is this not possible? Is this a bug or a design decision?
-
21 Jan 2011 8:13 PM #3
MMM, Why don't you just do an ajax request then?
not so bad, right?Code:var frmVals = this.getForm().getValues(); Ext.Ajax.request({ params: frmVals, url: this.url, ... });
Wes
-
22 Jan 2011 6:44 AM #4
How do I upload a file with an Ajax request?
-
22 Jan 2011 8:10 AM #5Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 44
You can't upload files with an Ext.Ajax request.
You have to use a form submit, which doesn't support setting headers.
-
24 Feb 2011 1:48 PM #6
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.
-
24 Feb 2011 11:42 PM #7Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 44
The missing piece of information here is that the 'headers' option is only valid when not doing a file upload.
-
30 Apr 2012 2:17 PM #8
'
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.
Similar Threads
-
Pass field how parameter from getForm().submit({
By chuvinha in forum Ext 3.x: Help & DiscussionReplies: 5Last Post: 4 Jan 2011, 10:36 AM -
Doubt arquivoForm.getForm().submit({
By chuvinha in forum Ext 3.x: Help & DiscussionReplies: 0Last Post: 4 Jan 2011, 10:27 AM -
Unable to submit from combo after myForm.getForm().setValues();
By cshamis in forum Ext 3.x: Help & DiscussionReplies: 2Last Post: 14 Sep 2010, 12:49 AM -
Can't submit my form (win.getForm() is not a function)
By michiel in forum Ext 2.x: Help & DiscussionReplies: 4Last Post: 23 Jun 2008, 7:16 AM


Reply With Quote