【发布时间】:2020-05-10 16:11:15
【问题描述】:
我无法在 php(symfony) 中访问我的数组,我不明白为什么有任何想法? 我尝试了一个对象
const obj= {
media: "facebook",
type: "fb_profile",
id: "2b48996c71bc33c8b5234e66cb81fe27a2a8d6233df0ac113b…a86c063ebe86bcfd21f10adc9caea5ff0eb4c3f20018c05dd"
}
或数组
const ary = [**strong text**
media: "facebook",
type: "fb_profile",
id: "2b48996c71bc33c8b5234e66cb81fe27a2a8d6233df0ac113b…a86c063ebe86bcfd21f10adc9caea5ff0eb4c3f20018c05dd"
]
这是我的 sjs 代码
el.addEventListener('click', function (e) {
const xhrConstruct = (method, url, data) => {
const promise = new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.open(method, url, true);
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
// xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.setRequestHeader('Content-Type', 'application/json');
// xhr.responseType = 'json';
xhr.onload = function (ev) {
resolve(xhr.response);
};
xhr.send(JSON.stringify(data));
});
return promise;
};
const getFeed = () => {
xhrConstruct('POST', 'feed', {
media: ary["media"], // or obj.media
type: ary["type"], // or obj.type
id: ary["id"] // or obj.id
}).then(responseData => {
console.log(responseData);
});
};
getFeed();
}, false);
我的 php(symfony) 很简单,我只想访问使用 tha ajax 发送的信息
public function feed(Request $request)
{
// if ajax
if($request->isXmlHttpRequest()){
var_dump($request->request);
var_dump($_POST);
var_dump($_GET);
die();
}
}
三个都是空的
object(Symfony\Component\HttpFoundation\ParameterBag)#95 (1) {
["parameters":protected]=>
array(0) {
}
}
array(0) {
}
array(0) {
}
知道如何访问数据提前谢谢你
【问题讨论】: