php接受ajax返回的json数组,使用其中的值

	$price=$_POST['data'];
    $price1=json_decode($price,true);
    $price2=$price1['price'];
    //这里的$price2获取的就是传入的值
```javascript
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>商品页面</title>
    <script src="../js/jquery-3.5.1.js" type="text/javascript" charset="utf-8"></script>
    <script src="../js/vue.js" type="text/javascript" charset="utf-8"></script>
</head>
</head>
<body>
    <div id="app">
        <table>
            <tr>
                <th>编号</th>
                <th>图片</th>
                <th>价格</th>
                <th>作者</th>
                <th>图片路径</th>
            </tr>
            <tr v-for="item in items">
                <td>{{item.id}}</td>
                <td>{{item.logo}}</td>
                <td>{{item.price}}</td>
                <td>{{item.author}}</td>
                <td>
                    <img :src=item.logo alt="" width="100px" height="100px">  
                </td>
                <td><button  @click="add(item)">添加购物车</button> </td>
            </tr>
        </table>
    </div>
    <script>
       new Vue({
			el: "#app",
			data: {
				items:[]
			},
			created: function () {
				var that = this;
				$.ajax({
					type: 'POST',
					url: '../php/showpy.php',
					success: function (data) {
						var json = JSON.parse(data);
						that.items=json;
                    },
                    
				})	
            },
            methods: {
                
                add(item){
                    let resdata=JSON.stringify(item);
                    //let resdata=JSON.stringify(item); 
                    console.log(resdata);
                   
                    $.ajax({
                        type: 'POST',
                        url: '../php/addcar.php',
                        data:{
                            //isbn: resdata['isbn'],
                            data:resdata
                        },
                        success: function (data) {
                               var json=JSON.parse(data);
                               alert(json);
                        }
                    })
                }
            },
            
		})	
    </script>
</body>
</html>
当前没有用户登录时,访问该页面,直接跳转到登录页面
	created: function () {
				var that = this;
				$.ajax({
					type: 'POST',
					url: '../php/shpcar.php',
					success: function (data) {
						var json = JSON.parse(data);
						if(json.flag){
							that.items=json;
						}else{
							location.href='../html/login.html';
						}
					},
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值