I have a large number of links in a page that need to send them to the other page upon user's request. User provides an email address and submit the form, the application is needed to send all the information nd the requested email address to the other page to be shown and sent to the provided email address.
<a href="1">a1</a>
<a href="2">a2</a>
.....
<a href="100">a100</a>
How can I send the href and name of all of them to the other page and receive them in the other end? The other end needs to populate the same so I need to use a loop to read the received information and create the same links there.
Sample
Page 1 has followings
<div id="links">
<a href="1">a1</a>
<a href="2">a2</a>
.....
<a href="100">a100</a>
</div>
Page 2 AFTER receiving the data need to show and email them all
<div id="yourLinks">
<a href="1">a1</a>
<a href="2">a2</a>
.....
<a href="100">a100</a>
</div>
Let's say I wrap all your href with a div tag.
<div id = "lol">
<a href="1">a1</a>
<a href="2">a2</a>
.....
<a href="100">a100</a>
</div>
<button type = "submit" id ="button" />
Now on javascript I can do something like
$("#button").click(function () {
var myVal = $("#lol").html();
$.ajax({
url: yourURL,
type: 'POST',
data: {htmlVal:myVal}
});
});
Now in the other PHP file that you are referencing through url can just do extract
$_POST["htmlVal"];
I don't think using .get or .post instead of .ajax would work. Cuz I tried a similar thing and didn't work for me. But, I hope this helps.
one method for sending data is to use a form with hidden fields and sending them via POST.
<form method="POST" action="page.php">
<input type="hidden" name="a1" value="a1_link" />
<button type="submit" id="button" />
</form>
Rabin's method may be more what you're looking for, though.
If you need to send data with relatively complex from a page to another you can do so with a POST request to the second page. The POST data should be XML or JSON. First you need to use JavaScript to extract the information from the first page and serialize it into a suitable format (say JSON). The second page can then retrieve the POST data and render it in the desired way.
You could also keep it server-side and save the data in $_SESSION when the user submits the form in the first page and retrieve it from the same place in the second page. This approach seems cleaner to me.