Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何接收一个用angularjs填充并由ajax发送到服务器端(PHP)的json对象?_Php_Json_Ajax_Angularjs Scope_Jsondecoder - Fatal编程技术网

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

如何接收一个用angularjs填充并由ajax发送到服务器端(PHP)的json对象?,php,json,ajax,angularjs-scope,jsondecoder,Php,Json,Ajax,Angularjs Scope,Jsondecoder,我有以下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发送

我有以下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);
我尝试使用$\u GET['name']接收数据,但没有成功

我的php代码:

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

我还试着做: $data=json_decode($_GET['data'])

但它们都不起作用


提前感谢

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

$jsonData=$\u GET['data']

然后您必须处理这个JSON对象,并且可以使用PHP函数
JSON\u decode
将其设置为一个数组

$arrayData=json\u decode($jsonData,true)


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

使用json$json=json_decode($url,true);然后访问$id=$json['id'][0];那么这有什么不对呢<代码>$jsonData=$_GET['data']
$arrayData=json\u decode($jsonData,true)
$item\u id=$\u GET['id']
文件内容(“hell.txt”,$item\u id)哪里定义了$_GET['id']?您不需要使用$\u GET变量遍历数组。我强烈建议你仔细阅读哦抱歉我的意思是:
$item\u id=$arrayData[0]['id']
文件内容(“hell.txt”,$item\u id)这有什么问题?这将导致1。您是否记得将
true
添加为
json_decode
的第二个参数,使其成为一个关联数组,我确实这样做了:S,可能是js方面的问题?因为我在ajax中为以下对象发送数据:
{“function”:“sellAccess”,“data”:$scope.sellAccessories}