我的脚本我想从ajax.php中读取并显示它们,并在我想要从数据库中获取的ajax.php中。我的问题是从数据库中获取不起作用!
echo
'<?php while ($row = mysqli_fetch_array($products)):?>
<div class="item-in-cart clearfix">
<div class="image">
<img src="images/<?php echo $row['id'] ?>" width="124" height="124" alt="cart item" />
</div>
<div class="desc">
<strong>
<a href="product.html">s</a>
</strong>
<span class="light-clr qty">
<a href="#" class="icon-remove-sign" title="Remove Item"></a>
</span>
</div>
<div class="price">
<strong></strong>
</div>
</div>';
<?php endwhile;?>
$(document).ready(function(){
$(".addCart").click(function(){
var id = $(this).val();
$.ajax({
type:'post',
url:'ajax.php',
data :{
id : 'id',
},
success : function (response) {
$('#cart').html(response);
}
});
});
});
答案 0 :(得分:1)
在AJAX的返回循环中,将所有结果放在变量中的一个连接字符串中。然后回显该变量作为ajax中的返回。
确保标签上有ID“cart”
ajax.php
let processoperatorchange2 t2s2 proc2 op op2=
let rec poc2 p = match p with
| Zero -> "0"
| Pproc (x) -> String.lowercase x
| In(chan, var, _, p, _) -> chan^"("^var^")"^op^(poc2 p); chan^"("^var^")"^op2^(poc2 p)
in poc2 proc2
然后将推送HTML数据块并将其插入购物车ID标签内,但也可以在调用ajax时,或者在插入之前,先清空购物车ID
<?php
$return = "";
while($row = mysqli_fetch_assoc($products)):
$id = $row['id'];
$return .= "<div class='item-in-cart clearfix'>
<div class='image'>
<img src='images/$id' width='124' height='124' alt='cart item' />
</div>
<div class='desc'>
<strong>
<a href='product.html'>s</a>
</strong>
<span class='light-clr qty'>
<a href='#' class='icon-remove-sign' title='Remove Item'></a>
</span>
</div>
<div class='price'>
<strong></strong>
</div>
</div>";
endwhile;
echo $return;
?>