React JS中的JSON值叫做formdata
{
account_id: account_id? account_id : "null",
name: "",
email: "",
password: "",
is_active: true,
filters:{
minBlockRate: 20,
minRatePerHour: 10,
hours: {
startTime: "00:00",
endTime: "23:55",
},
weekdays: {
Monday: true,
Tuesday: true,
Wednesday: true,
Thursday: true,
Friday: true,
Saturday: true,
Sunday: true
},
warehouses: [],
},
timezone: "America/New_York",
}
这是通过Axios发送的
axios.post(ProjectConfig.api_url, null,
{
headers:{
'LTKN': cookies.get('ltkn'),
},
params: {
request: 'login',
formdata: formValues
}
})
.then((response) => {
.... REST OF CODE
当PHP API接收到这个消息时,键/值仓库被删除。
这是如何接收值的方法。
case 'login':
$formdata = $_REQUEST['formdata'];
$manual_token = $_REQUEST['manual_token'];
如果我对$formdata执行json_encode,结果是{ "account_id":"null", "name":"Juan", "email":"ambarmalave@yahoo.com", "password":"123", "is_active":"true", "filters":{ "minBlockRate":"20", "minRatePerHour":"10", "hours":{ "startTime":"00:00", "endTime":"23:55" }, "weekdays":{ "Monday":"true", "Tuesday":"true", "Wednesday":"true", "Thursday":"true", "Friday":"true", "Saturday":"true", "Sunday":"true" } }, "timezone":"America\/New_York" }
我不知道这里的问题在哪里。React或PHP
附加信息。
- React js / axios,像JSON一样发送JSON对象,所以,我不需要使用json_decode来格式化它。
1条答案
按热度按时间kqqjbcuj1#
当然,json对象应该被POST并作为主体接收,而不是作为参数。
使用PHP接收如下: