Javascript 如何根据来自另一个页面的数据来放置页面内容
我有一个页面(menu.php),可以从数据库中检索和显示数据,包括名称、图像和价格 我想在单击图像时添加一个链接,将我带到另一个页面(single Product.php),因此我只有一个页面,我希望它的内容取决于我单击的图像Javascript 如何根据来自另一个页面的数据来放置页面内容,javascript,php,ajax,database,get,Javascript,Php,Ajax,Database,Get,我有一个页面(menu.php),可以从数据库中检索和显示数据,包括名称、图像和价格 我想在单击图像时添加一个链接,将我带到另一个页面(single Product.php),因此我只有一个页面,我希望它的内容取决于我单击的图像 <div class="row"> <div class="col-md-9"> <div class="products-heading"> <h2>Our Salad</h
<div class="row">
<div class="col-md-9">
<div class="products-heading">
<h2>Our Salad</h2>
</div> <!-- End of /.Products-heading -->
<div class="product-grid">
<div class="row">
<?php
require('connection.php');
extract($_POST);
$rc=mysql_query("select * from menu where Item_Catagory = 'Salad'") or die(mysql_error());
while($MenuItem=mysql_fetch_array($rc))
{
?>
<!--To send item info to single-product page -->
<div class="col-md-4">
<div class="products">
<a href="single-product.php" >
<img src="images/<?php echo $MenuItem['Item_Image']; ?>" alt="" />
</a>
<a href="single-product.php">
<h4> <?php echo $MenuItem['Item_Name']?> </h4>
</a>
<p class="price"> <?php echo $MenuItem['Item_Price']?></p>
<div class="row lead">
<center><div id="stars" class="starrr"></div></center>
</div>
<a class="view-link shutter" href="#">
<i class="fa fa-plus-circle"></i>Add To Cart</a>
</div> <!-- End of /.products -->
</div> <!-- End Of /.Col-md-4 -->
<?php }
?>
</div> <!-- End of /.row -->
我们的沙拉
使用id发送数据:
更改
到<代码>
$('a').click(function(){
$.ajax({
url: this.href,
method: 'GET',
success: function(response){
console.log(response);
//here you can append the response to your html
}
});
return false; //prevent browser from redirecting
});