Marilee Marilee - 1 year ago 52
jQuery Question

Send PHP Link data from ajax call to different page onclick

Im busy learning ajax. I have a reservation page and a checkout page.

What I want to do

User types the renter name into a search box, matching names gets fetched from db and displayed dynamically.

Like so:


enter image description here

When user clicks the highlighted link, I would like the reservation Id to get passed to the checkout page. THUS, Im looking for a way to pass the reservation ID to another/different page, which I can use for data processing on the checkout page.


enter image description here



$(document).ready(function () {
$("#searchbox").on('keyup',function () {
var key = $(this).val();

beforeSend:function () {
success:function (data) {
<div id="main">
<div id="header"><h1>Find Names</h1></div>
<div id="content">
<input type="search" name="keyword" placeholder="Search Names" id="searchbox">
<div id="results"></div>


if($_GET['keyword'] && !empty($_GET['keyword']))
$conn = mysqli_connect('localhost','root','','*****'); //Connection to my database
$keyword = $_GET['keyword'];
$query = "select renter_name from reservations where renter_name like ?";
$statement = $conn->prepare($query);
if($statement->num_rows() == 0) // so if we have 0 records acc. to keyword display no records found
echo '<div id="item">Ah snap...! No results found :/</div>';

else {
while ($statement->fetch()) //outputs the records
echo "<div id='item'>$name</div>";


enter image description here

Any help or advice in terms of implementation greatly appreciated!

Answer Source

Simply use links and queries. At first echo a link instead of a div:

echo "<a href='yourpage.php?id=$name'>$name</a>";

And on your page simply do:

echo $_GET[" id"];