I have a submit input in a form with an onclick method. The onclick method correctly adjusts the action of the form and allows the form to submit (submission is handled naturally, not through a javascript submit). What I need to do is add a http request header (X-Requested-With = XMLHttpRequest to be exact). Is there a way to ensure the form post is sent with that header? The post cannot be submitted via javascript using the form.submit() method.
Asked
Active
Viewed 342 times
1 Answers
0
According to this answer what you're asking for is impossible in its current form. However you could modify where the form submits too. For example POST to:
www.mysite.com/XMLHttpRequest
or www.mysite.com/NormalRequest
so that the server understands the context of the request.

Community
- 1
- 1

m.edmondson
- 30,382
- 27
- 123
- 206
-
My issue is that I have a method that checks the http request header to see if it is an ajax call. Now, without realizing I would need it, I'm having to do a normal POST call. Without that added header as a check, the page will not load correctly. The AJAX javascript in the answer you posted is what I need, only I need it for form posts instead. – steventnorris May 30 '12 at 19:05
-
Can you not modify your method? – m.edmondson May 30 '12 at 19:08
-
I could. I plan to use a hidden field check to determine whether the header should even be checked in the first place. I was just hoping to use the same bit across the board. Thanks! – steventnorris May 30 '12 at 19:17