views:

110

answers:

1

Hello stackoverflowers, hope you all are doing great.

I admit I got kinda confused with Http requests and responses, so I'll begin by presenting my problem.

I made a webpage that takes user input, processes it and uses XMLHttpRequest POST to send the processed data to another page and display said data into said page.

Now, I can form the XMLHttpRequest using POST just fine, as well as successful redirection; but what I want to actually do is have the second page display the POSTed data.

How can I let the second page read and display the data encapsulated in the POST request in a successful redirection from the first page?

Here is my XMLHttpRequest code, in javascript:

var xmlhttp= new XMLHttpRequest()

 xmlhttp.open('POST',"Default2.aspx",false);
  xmlhttp.setRequestHeader('Content-Type',
'application/x-www-form-urlencoded');
 xmlhttp.setRequestHeader("Connection", "close");

xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            window.location = "Default2.aspx";
            }
}

  xmlhttp.send(""+x);

I want to handle the POSTed data in the second page in javascript or ASP.NET. Thank you for your time!

+4  A: 

It sounds like you shouldn't be using AJAX / XMLHttpRequest at all. Just create a form that posts to the second page like normal, ie:

<form action="Default2.aspx">
  <!-- put the form elements here -->
  <input type="submit" value="Submit">
</form>

XMLHttpRequest is for getting server-side data from a different page/script and doing something with that data without leaving the current page. When you want to leave the current page you just use a form, as has been the standard for 15+ years.

DisgruntledGoat
Thanks for the answer, but how can I encapsulate some particular data in the request using a form? What about processing the request in the second page(to display the data) ?
Voulnet