[英]How to send data from 2 different page to a php via an ajax call together?
[英]Send PHP Link data from ajax call to different page onclick
我忙於學習ajax。 我有一個預訂頁面和一個結帳頁面。
我想做的事
用戶在搜索框中鍵入承租人名稱,將從數據庫中獲取匹配的名稱並動態顯示。
像這樣:
Reservations.php
當用戶單擊突出顯示的鏈接時,我希望預訂ID傳遞到結帳頁面。 因此, 我正在尋找一種將預訂ID傳遞到另一個/不同頁面的方法,我可以將其用於結帳頁面上的數據處理。
checkout.php
碼
搜索/查詢
$(document).ready(function () {
$("#searchbox").on('keyup',function () {
var key = $(this).val();
$.ajax({
url:'fetch.php',
type:'GET',
data:'keyword='+key,
beforeSend:function () {
$("#results").slideUp('fast');
},
success:function (data) {
$("#results").html(data);
$("#results").slideDown('fast');
}
});
});
});
</script>
<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>
</div>
</div>
FETCH.PHP
if($_GET['keyword'] && !empty($_GET['keyword']))
{
$conn = mysqli_connect('localhost','root','','*****'); //Connection to my database
$keyword = $_GET['keyword'];
$keyword="%$keyword%";
$query = "select renter_name from reservations where renter_name like ?";
$statement = $conn->prepare($query);
$statement->bind_param('s',$keyword);
$statement->execute();
$statement->store_result();
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>';
$statement->close();
$conn->close();
}
else {
$statement->bind_result($name);
while ($statement->fetch()) //outputs the records
{
echo "<div id='item'>$name</div>";
};
$statement->close();
$conn->close();
};
};
D B
在實施方面的任何幫助或建議,我們將不勝感激!
只需使用鏈接和查詢。 首先,回顯一個鏈接而不是一個div:
echo "<a href='yourpage.php?id=$name'>$name</a>";
在您的頁面上只需執行以下操作:
<?php
echo $_GET[" id"];
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.