php - 如何接收用 angularjs 填充并由 ajax 发送到服务器端(PHP)的 json 对象?
问题描述
我有以下 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']);
但它们都不起作用!
提前致谢
解决方案
您需要根据 url 查询检索数据。因此,例如,如果您需要 JSON 数据,那么您可以通过以下方式检索 JSON
$jsonData = $_GET['data'];
然后你必须处理这个 JSON 对象,你可以json_decode
像这样使用 PHP 函数使它成为一个数组
$arrayData = json_decode($jsonData, true);
然后,您可以像任何其他数组一样遍历所述数据。
推荐阅读
- rest - 使用 Dynamics 365 Web api 创建记录时跳过字段验证
- java - Volley 似乎不适用于 Android SDK 29
- jquery - jquery-selective隐藏条件上的删除图标
- apache-kafka - Couchbase kafka 源连接器消息顺序
- python - 修复将二进制数据写入文件的问题:“文件不是 UTF-8 编码的”
- php - PHP:以浮点数计算完整年龄
- docusignapi - 需要有关 DocuSign 电子签名网址的帮助?
- reactjs - 在没有消费者的情况下使用 contexProvider 会被认为是不好的做法吗
- javascript - 如何从 Node.js 中的回调函数中获取返回值?
- php - 类 google.cloud.speech.v1.LongRunningRecognizeMetadata 尚未添加到描述符池