我想通过ajax php将一些数据从mysql加载到div。自动递增的 id 字段始终为零。
我曾尝试使用 get、post 等,但都没有工作
<script>
$(document).ready(function(){
$(document).on('click', '#getUser', function(e){
e.preventDefault();
var uid = $(this).data("customer_id"); // it will get id of clicked row
$('#txtHint').html(''); // leave it blank before ajax call
$('#mySidenav').show(); // load ajax loader
$.ajax({
url: 'getCustomerDetails.php',
type: 'GET',
data: 'customer_id='+uid,
dataType: 'html'
})
.done(function(data){
console.log(data);
$('#txtHint').html('');
$('#txtHint').html(data); // load response
$('#modal-loader').hide(); // hide ajax loader
})
.fail(function(){
$('#txtHint').html('<i class="glyphicon glyphicon-info-sign"></i> Something went wrong, Please try again...');
$('#modal-loader').hide();
});
});
});
</script>
<?php
include_once('../../config/dbconfig.php');
if (isset($_REQUEST['customer_id'])) {
$id = intval($_REQUEST['customer_id']);
$query = "SELECT * FROM customers WHERE customer_id=:id";
$stmt = $pdo->prepare( $query );
$stmt->execute(array(':id'=>$id));
$row=$stmt->setFetchMode(PDO::FETCH_ASSOC);
?>
<div class="row">
<div class="col-md-1">
<div class="col-md-4" >
<?php echo $row['first_name'];?>
</div>
<div class="col-md-6">
</div>
</div>
</div>
<?php echo $id;?><br/>
<?php
}
?>
结果不回显 firs_name 因为 $id 始终为 0。我想在完成后获取个人 $id(auto_increment) 它应该显示用户记录
holdtom
大话西游666