前台的代码:
const req = {
name: 'Wing',
age: 32,
skills: ['HTML', 'CSS', 'JavaScript']
};
fetch('/actions/user/info', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(req)
}).then(response => response.json())
.then(json => {
console.log(json);
});
后端用的PHP,现在我用file_get_contents("php://input");能获取到传过来的数据,可是拿到的是原始的一个JS 对象,要如何转换成PHP数组呢?
或者,还能有其他办法来获取数据么?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
这样过去的应该是JSON格式:
http://www.ruanyifeng.com/blog/2011/01/json_in_php.html