html代码:
<a href="javascript:void(0)" onClick="one()" value="62" class=aa>点击</a>
<div id=bb></div>
现在通过js传值给php,php运行后怎么把值返回来,
js代码:
<script>
$(function(){
$(".aa").on('click', function(event) {
var id = $(".aa").attr("value");
$.ajax({
url: 'yx.php',//重点
type: 'POST',
dataType: 'json',
data: {id: id}, }); });});</script>
php代码:
$id = $_POST["id"];
$sql = "select * from table where id = '$id'";
$obj = mysqli_query($conn,$sql);
$row = mysqli_fetch_assoc($obj) ;
echo $row['data'];
现在就是希望$row['data']返回到<div id=bb></div>这里面
<script>
$(function(){
$(".aa").on('click',function(event){
var id = $(".aa").attr("value");
$.ajax({
url: 'yx.php',
type: 'POST',
dataType: 'json',
data: {id: id},
success: function(data){
$("#bb").html(data);
}
});
});
});
</script>
$(function(){
$(".aa").on('click',function(event){
var id = $(".aa").attr("value");
$.ajax({
url: 'yx.php',
type: 'POST',
dataType: 'json',
data: {id: id},
success: function(data){
$("#bb").html(data);
}
});
});
});
</script>
温馨提示:答案为网友推荐,仅供参考
第1个回答 2018-09-20
AJAX 里边的代码 success:里边 还要写完