js 传值php 怎么获取返回变量
html代码:<ahref="javascript:void(0)"onClick="one()"value="62"class=aa>点击</a><divid=bb><...
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>这里面 展开
<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>这里面 展开
2个回答
展开全部
<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>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询