php - 在php中提取json
问题描述
你好,
那里有我的ajax代码
//If chkArray is not empty show the <div> and create the list
if(chkArray.length !== 0) {
$.ajax({
method: 'POST',
url : 'http://localhost/shop/ext/ajax/products_compare/test.php',
// data : JSON.stringify({product_id: chkArray})
data: {product_id: JSON.stringify(chkArray)},
});
}
我有这样的结果:
array(1) {
["{"product_id":"]=>
array(1) {
[""10","9""]=>
string(0) ""
}
}
如何在 php 中提取此代码?
解决方案
无需使用 JSON.stringify,只需传递原始值数组:
$.ajax({
method: 'POST',
url : 'http://localhost/shop/ext/ajax/products_compare/test.php',
data: {product_id: chkArray},
});
在服务器端,您将拥有$_POST['product_id']
带有值的数组。
推荐阅读
- amazon-web-services - AWS:将 ASG 附加到 EKS 集群
- java - 如何在 java 中将 1 显示为 01?
- javascript - 如何在不添加任何层次结构的情况下将列表的某些元素显示为粘性元素?
- google-analytics - 谷歌分析页面跟踪停止工作
- java - 400 错误请求。在 JMeter 中测试的 Java 中发送 HTTP POST 调用
- reactjs - 设置“选择文件”按钮的样式
- angular - 自动调整 mat-header-cell 中的输入宽度
- python - python中R的“制表”和“C”的等价物
- php - 为什么刀片指令仍然可见?
- vue.js - vue-chartjs 圆环图百分比显示