-1

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.com/thsutton/665306

https://developer.mozilla.org/en-US/docs/Web/API/Headers

enter image description here

Community
  • 1
  • 1
Pranav Shah
  • 91
  • 1
  • 2
  • 12

1 Answers1

2

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

Scott Marcus
  • 64,069
  • 6
  • 49
  • 71
  • it uses POST method – Pranav Shah Nov 17 '16 at 18:29
  • @PranavShah Then, as I said, the data will be sent to the destination as a stream and you'll use server-side code to access it. Look at the article I provided (in particular the "On the server side: retrieving the data" section). – Scott Marcus Nov 17 '16 at 18:31
  • thank you for sharing informative Link can we do the same in JS !! – Pranav Shah Nov 17 '16 at 18:36
  • 1
    @PranavShah As I've been saying, form data is processed on the server, not the client. – Scott Marcus Nov 17 '16 at 18:39
  • Okay so can you suggest a way out... What i want to do is i wanted to POST some data from one Domain to another Domain (basically some parameters) so i thought this would be a good way to do so. Reason i wanted to use those parameters values in further process. – Pranav Shah Nov 17 '16 at 18:42
  • @PranavShah Yes, I would suggest that you do exactly what I've been saying and look at a server-side solution. – Scott Marcus Nov 17 '16 at 18:47
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/128386/discussion-between-pranav-shah-and-scott-marcus). – Pranav Shah Nov 17 '16 at 18:50