我使用以下手风琴显示两个结果不同的查询:手风琴显示查询中的一行,而我使用AJAX调用第二个查询来填充手风琴内容区域。这是我的代码和问题:
我收到以下错误:
错误:[object XMLHttpRequest]
这是我的代码:
手风琴
<div class="wrapper" >
<div class="accButton" id="<?php echo $name; ?>"> //this value comes from the query and is passed to the AJAX call
<span class="namecustcoltype"><?php echo $record; ?></span>
<span class="namecusttype"><?php echo $name; ?></span>
//Accordian content area- This div accepts the return from the AJAC call
<div class="accContent" id="output_element">
</div>
</div> //closing div for accordian button
AJAX致电
<script type="text/javascript">
$(document).ready(function() {
$('.accButton').click(function() {
var element = $(this);
var del_id2 = element.attr("id");
$.ajax({
type: "POST",
url: "item_view.php",
//data: info,
data: {id2:del_id2},
success: function(response){
$("#output_element").html(response);
},
error: function(msg){
alert("Error: "+msg);
}
});
});
});
</script>
item_view.php
<?php
include('db.php');
$id = $_POST['id2'] ;
$name = $_POST['order_id'] ;
$sql = "SELECT * FROM mgap_orders WHERE mgap_ska_id = '$id' GROUP BY mgap_item_description LIMIT 5";
$stmt = $pdo->prepare($sql);
$items = array();
$stmt->execute(array(':id' => '$id'));
while($row_cat_sub = $stmt->fetch(PDO::FETCH_ASSOC))
{
$items['item']=$row_cat_sub['mgap_item_description'];
$items['item_num']=$row_cat_sub['mgap_item_number'];
$items['item_type']=$row_cat_sub['mgap_item_type'];
$items['item_cat']=$row_cat_sub['mgap_item_catalog_number'];
$items['item_ven']=$row_cat_sub['mgap_item_vendor'];
$items['item_pur']=$row_cat_sub['mgap_item_percent_purchased'];
$items['item_sales']=$row_cat_sub['mgap_item_sales'];
}
foreach($items as $item) {
?>
<span class="namecustcoltype"><?php echo $item; ?></span>
<span class="namecusttype"><?php echo $item_num; ?></span>
<span class="growthcust">$<?php echo $item_type; ?></span>
<span class="namecustcoltype"><?php echo $item_cat; ?></span>
<span class="namecusttype"><?php echo $item_ven; ?></span>
<span class="growthcust">$<?php echo $item_pur; ?></span>
<span class="growthcust">$<?php echo $item_sales; ?></span>
<?php
}
?>