Javascript AJAX显示相同的MySQL查询结果,即使更改了发送的数据
我正在运行一个AJAX函数,它将数据发送到一个页面,在该页面上运行MySQL查询并显示结果 单击此按钮可启动该功能 这是查询和显示数据库的URLJavascript AJAX显示相同的MySQL查询结果,即使更改了发送的数据,javascript,php,jquery,mysql,ajax,Javascript,Php,Jquery,Mysql,Ajax,我正在运行一个AJAX函数,它将数据发送到一个页面,在该页面上运行MySQL查询并显示结果 单击此按钮可启动该功能 这是查询和显示数据库的URL &时代; “alt=”“class=“详细信息img响应”> 细节 价格: 品牌: ) 接近 添加到购物车 $('#size')。更改(函数(){ 可用变量=$('大小选项:选定')。数据('可用'); $('可用').val(可用); }); 函数closeModal(){ $(“#详细信息模式”).model('hide'); setTime
&时代;
“alt=”“class=“详细信息img响应”>
细节
价格:
品牌:
)
接近
添加到购物车
$('#size')。更改(函数(){
可用变量=$('大小选项:选定')。数据('可用');
$('可用').val(可用);
});
函数closeModal(){
$(“#详细信息模式”).model('hide');
setTimeout(函数(){
$(“#详细信息”).remove();
$('.modal background').remove();
},500);
};
问题是,即使我发送不同的数据,我也会得到相同的MySQL结果。当你查询数据库时,你能检查SQL语句是否不同吗?你能给我们一些例子说明什么URL产生了什么SQL语句吗?你的
数据类型声明在ajax
方法中在哪里?
<div class="text-center">
<button type="button" class="btn btn-sm btn-success" onclick="detailsmodal(<?php echo $product['id']; ?>)">Details</button>
</div>
function detailsmodal(id){
var data = {"id" : id};
$.ajax({
url : '/php-ecom/includes/details-modal.php',
method : "post",
data : data,
success : function(data){
$('body').append(data);
$('#details-modal').modal('toggle');
},
error : function(){
alert('something went wrong');
}
});
};
<?php
require_once '../core/init.php';
$id = $_POST['id'];
$id = (int)$id;
$sql = "SELECT * FROM products WHERE id = '$id' ";
$result = $db->query($sql);
$product = mysqli_fetch_assoc($result);
$brand_id = $product['brand'];
$sql2 = " SELECT brand FROM brand WHERE id = '$brand_id' ";
$brand_query = $db->query($sql);
$brand = mysqli_fetch_assoc($brand_query);
$sizestring = $product['sizes'];
$size_array = explode(',', $sizestring);
?>
<?php ob_start(); ?>
<div class="modal fade details-1" id="details-modal" tabindex="-1" role="dialog" aria-labelledby="details-1" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button class="close" type="button" onclick = "closeModal()" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title text-center"><?php echo $product['title']; ?></h4>
</div>
<div class="modal-body">
<div class="container-fluid">
<div class="row">
<span id="modal_errors" class="bg-danger"></span>
<div class="col-sm-6">
<div class="center-block">
<img src="<?php echo $product['image']; ?>" alt="<?php echo $product['title']; ?>" class="details img-responsive">
</div>
</div>
<div class="col-sm-6">
<h4>Details</h4>
<p><?php echo $product['description']; ?></p>
<hr>
<p>Price: <?php echo $product['list_price']; ?></p>
<p>Brand: <?php echo $brand['brand']; ?></p>
<form action="add_cart.php" method="post" id="add_product_form">
<input type="hidden" name="product_id" value="<?=$id; ?>">
<input type="hidden" name="available" id="available" value="">
<div class="form-group">
<div class="col-xs-3">
<label for="quantity">Quantity:</label>
<input type="number" class="form-control" id="quantity" name="quantity">
</div>
<p>Available: 3</p>
</div><br>
<div class="form-group">
<label for="size"></label>
<select name="size" id="size" class="form-control">
<option value="">options</option>
<?php foreach($size_array as $string){
$string_array = explode(':',$string);
$size = $string_array[0];
$available = $string_array[1];
?>
<option value="<?php echo $size; ?>" data-available="<?=$available ?>"><?php echo $size; ?> (Available: <?php echo $available; ?>)</option>
<?php }; ?>
</select>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-default" onclick="closeModal()">Close</button>
<button class="btn btn-warning" onclick="add_to_cart(); return false;"><span class="glyphicon glyphicon-shopping-cart"></span> Add To Cart </button>
</div>
</div>
</div>
</div>
<script>
$('#size').change(function(){
var available = $('#size option:selected').data('available');
$('#available').val(available);
});
function closeModal(){
$('#details-modal').modal('hide');
setTimeout(function(){
$('#details').remove();
$('.modal-backdrop').remove();
},500);
};
</script>
<?php echo ob_get_clean(); ?>