ygongdev ygongdev - 1 year ago 70
jQuery Question

How to send data from 2 different page to a php via an ajax call together?

So I need the user to fill a form and then I want to pass that data to another page like so


<form action="site2.php" method="post">
Name: <input type="text" name="name">
Email: <input type="text" name="email">
<input type="submit">

Site2 will read the name and email from site1 and include it inside a ajax call

Site2 Javascript

function addMarker(location, map) {
// Add the marker at the clicked location
var marker = new google.maps.Marker({
position: location,
map: map

url: 'insertToDatabase.php',
type: 'POST',
data: { lat: location.lat(),
long : location.lng(),
name : $_POST['name'], // something like this
email: $_POST['email'] // something like this

Is there a way to do something like this for the Ajax call?

Answer Source

Sure. in site2, just capture the POST vars, then ask PHP to print their values wherever you need it


//capture the POST vars
$name = $_POST['name'];
$email = $_POST['email'];
...HTML & JS code GOES HERE....

Then later on down the page, where your ajax function is, you can re-enter PHP mode to output the values:

    url: 'insertToDatabase.php',
    type: 'POST',
    data: { lat: location.lat(),
    long : location.lng(),
    name : '<?= $name ?>',
    email: '<?= $email ?>'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download