My question is very simple can we get Form data values from HTTP request body of Network(DOM window).
As you can see in image there is Form data I wanted to get those data and store that into some local variable on same page.
I am able to get and store HTTP headers value but whenever I tried to get Form data it returns NULL. Can anyone confirm even its possible.
Can we store results into variable/text-box!!
For example in image I have three values.
cmp :131,
biz : 2001,
biz_name :Demo + gents + tailor
can we store this values into some variable like,
var cmp = 131
var biz = 2001,
var biz_name = Demo gents tailor
Code for the same which will redirect me to particular page :
var redirect = 'myurl';
$.extend(
{
redirectPost: function(location, args)
{
var form = '';
$.each( args, function( key, value ) {
form += '<input type="hidden" name="'+key+'" value="'+value+'">';
});
$('<form action="'+location+'" method="POST">'+form+'</form>').appendTo('body').submit();
}
});
$.redirectPost(redirect, {cmp:131,biz:2001,biz_name:"Demo gents tailor"});
Refered Links : Accessing the web page's HTTP Headers in JavaScript
How do I access the HTTP request header fields via JavaScript?
jquery - get http headers
My question is very simple can we get Form data values from HTTP request body of Network(DOM window).
As you can see in image there is Form data I wanted to get those data and store that into some local variable on same page.
I am able to get and store HTTP headers value but whenever I tried to get Form data it returns NULL. Can anyone confirm even its possible.
Can we store results into variable/text-box!!
For example in image I have three values.
cmp :131,
biz : 2001,
biz_name :Demo + gents + tailor
can we store this values into some variable like,
var cmp = 131
var biz = 2001,
var biz_name = Demo gents tailor
Code for the same which will redirect me to particular page :
var redirect = 'myurl';
$.extend(
{
redirectPost: function(location, args)
{
var form = '';
$.each( args, function( key, value ) {
form += '<input type="hidden" name="'+key+'" value="'+value+'">';
});
$('<form action="'+location+'" method="POST">'+form+'</form>').appendTo('body').submit();
}
});
$.redirectPost(redirect, {cmp:131,biz:2001,biz_name:"Demo gents tailor"});
Refered Links : Accessing the web page's HTTP Headers in JavaScript
How do I access the HTTP request header fields via JavaScript?
jquery - get http headers
https://gist.github./thsutton/665306
https://developer.mozilla/en-US/docs/Web/API/Headers
Share Improve this question edited May 23, 2017 at 12:24 CommunityBot 11 silver badge asked Nov 17, 2016 at 18:23 Pranav ShahPranav Shah 911 gold badge4 silver badges12 bronze badges 2- Form data doesn't exist in the headers - it's in the request body – Rory McCrossan Commented Nov 17, 2016 at 18:25
- okay pardon me will change it – Pranav Shah Commented Nov 17, 2016 at 18:26
1 Answer
Reset to default 2You don't get the data from the headers, per se. You get them from the HTTP Request and Response (which if you look at the developer tools tab you are on, you will see it says "Response").
When a form submits its data, the data is sent as name/value pairs to the location specified in the HTML <form>
element's action
attribute. Since that file exists on a server, that file typically contains server-side code (such as .php or .jsp or .aspx) and the form's data is processed by that code (via accessing the HTTP Request object).
Now, depending on how the form sent the data (GET or POST), that will determine exactly how the server-side code will access the request. If GET was used, the form data will be persisted in the URL as a query string. If POST was used, the data is sent as a stream.
Take a look at this article, which explains the process quite well.