I have two php pages. Page 1 contains one form which i submitted with jQuery. Page 2 is form query page. I want to read all the data from Page 2 after submitting from page 1 through navigation. My following code does not work as I expected.
Page 1:
$.ajax({
type: "POST",
url: "requestProcessor.php",
data: "fname="+ fname +"& lname="+ lname,
success: function(){
window.location.href = "requestProcessor.php";
}
});
Page 2: requestProcessor.php
<?php
require("db/phpsql_info.php");
echo htmlspecialchars(trim($_POST['fname']));
echo htmlspecialchars(trim($_POST['lname']));
?>
Thanks in advance..
First, change your data parameter to:
It’s more readable.
2nd, it does not make sense what you are doing. You are posting data to requestProcessor.php, then after that you send the user to requestProcessor.php (which is then a GET). This loses all the POST data from before of course as it’s the equivalent of just typing requestProcessor.php into your URL bar.
If you want to go from page 1 to page 2 and see the data POSTed then just submit your form on page 1 to requestProcessor.php directly.
Else, if you want to show the result of page 2 after the POST, then send the response to some div on the current page.
Not sure what you are trying to achieve though if I am honest.