关于一个请求的问题

weixin_39804852 2018-05-28 09:11:12
谁能帮我看下的代码问题吗
微信端:
pay: function () {
var token = wx.getStorageSync('token');
var that = this;
var jsond;
wx.request({
url: 'http://zerg.me/api/v1/order?XDEBUG_SESSION_START=1757',
header: {
"token": token,
"content-type": "application/x-www-form-urlencoded"
},
data: {
products: [
{
"product_id": 1, "count": 1
},
{
"product_id": '1', "count": 1
}
]
},
method: 'POST',
success: function (res) {
console.log(res.data);
}
})
},

服务器端 :
// print_r( json_decode($_POST['products'],true) );
print_r($_POST);
die;

为什么会输出 、
Array
(
[products] => [object Object],[object Object]
)
当我用ajax请求的时候就能正确输出出来

Array ( [products] => Array ( [0] => Array ( [product_id] => 1 [count] => 1 ) [1] => Array ( [product_id] => 1 [count] => 1 ) ) )

请问原因是什么



...全文
1369 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuzuning 2018-05-31
  • 打赏
  • 举报
回复
"content-type": "application/json" 见 http://www.phpos.net/xiaochengxu/api/561.html
ayzen1988 2018-05-31
  • 打赏
  • 举报
回复
直接用var_dump
木秀猿林 2018-05-29
  • 打赏
  • 举报
回复
一个是对象一个是数组。
yt_php 2018-05-28
  • 打赏
  • 举报
回复
那是因为它不是ajax 转成数组不就得了

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧