如何接收由 ajax 填充并由 ajax 发送到服务器端 (PHP) 的 json 对象?

How to receive a json object filled up with angularjs and sent by ajax to server side (PHP)?

我有以下 json 对象:

$scope.sellAccessories=
 [
 {"id": "1","name": "aa", "quantity": "3","total_price": "100"}
 ,
 {"id": "2","name": "bb", "quantity": "4","total_price": "200"}
 ,
 {"id": "3","name": "cc", "quantity": "5","total_price": "300"}
];

我使用 ajax 发送对象如下:

var options={
    type : "get",
    url : "../php/sell.php",
    data: {"function":"sellAccess","data":$scope.sellAccessories},
    dataType: 'json',
    async : false,
    cache : false,
    success : function(response,status){
        alert("success")
    },
    error:function(request,response,error){
        alert("error")
    }
};
$.ajax(options);

我尝试使用 $_GET['name'] 接收数据,但没有成功

我的php代码:

$item_name=json_decode($_GET['name']);

我也尝试过: $data=json_decode($_GET['data']);

但其中 none 个有效!

提前致谢

您需要根据 url 查询检索数据。因此,例如,如果您需要 JSON 数据,那么您可以通过执行

来检索 JSON

$jsonData = $_GET['data'];

然后你必须处理这个 JSON 对象,你可以像这样使用 PHP 函数 json_decode 使它成为一个数组

$arrayData = json_decode($jsonData, true);

然后你可以像遍历任何其他数组一样遍历所述数据。