How do i pass headers when specifying a location with window.location.href

HI,
Currently i am on a html page which has an submit button. And when that button is clicked the user goes to the url :
url?validation=...& etc
This is achived by setting a on click listener on submit button and executing :
window.location.href =url?validation=...
How do i achive the same if i want to pass this validation in the headers... Is there any way i can specify headers with window.location.href ??
OR any alternative way to achive the same using javascript etc.


Thanks
Rohit BajajAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

James BilousSoftware EngineerCommented:
Why don't you just submit the form using a post, no javascript required.
0
Julian HansenCommented:
What do you mean by headers? Are you referring to the form variables on the page.

It is possible to do this. You could use JQuery - something like this

<script src="http://code.jquery.com/jquery.js"></script>
<script>
$(function() {
    $('form').submit(function(e) {
      window.location.href = url + '?' + $(this).serialize();
      return false;
    });
});
</script>

Open in new window

If you mean in the actual headers then I don't think you can do that with windows.location as the request is being made by the browser.

You can modify the headers with an AJAX call.

Can you give us more information about the use case - what is it you are trying to achieve.
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rohit BajajAuthor Commented:
i mean the actual headers. the way we specify headers in an ajax call. but i think ajax call wont transfer me to another page it will just take a request and will get the response in the callback.
my aim is to actually to transfer the user to another page. but the validationID etc fields dont seem right in the query parameters logically.   Although i do achieve what i want to achieve using location.href ... that is transfer the user to other page and i embed this validationId in the resulting page
0
James BilousSoftware EngineerCommented:
Why don't you either A) Redirect upon successful completion of the ajax call or B) set the form method as post and submit it using a submit button. Why are you using window.location - what you are trying to do is the default behavior of a form with no javascript.
0
Julian HansenCommented:
Can you give me an example of how you would do this with AJAX - just want to make sure I understand exactly what you are asking.

Why do you need to embed information in the header - there is scope for this in some applications but the usual method of data transfer is in the URL (parameters retrieved with a GET) or as POST data. Why specifically do you need to modify the headers
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.