我正在使用Symfony4,并且试图从Request中获取POST参数。使用:
$request = Request::createFromGlobals();
$email = $request->request->get('email');
让我为空,但如果我这样做:
$request = Request::createFromGlobals();
var_dump($request->request->all());
我可以看到email参数已经设置并且具有一定的价值。 我的问题是:如何获取该参数值?
我在这里发布了一段代码:
/**
* @Route("/prenota/appuntamento/salva", name="app_habiter_calendario_save", methods={"POST"})
*/
public function salvaPrenotazione(ValidatorInterface $validator){
$request = Request::createFromGlobals();
$entityManager = $this->getDoctrine()->getManager();
$prenotazioni = new Prenotazioni();
$clienti = new Clienti();
$email = $request->request->get('email');
[...]
}
的屏幕截图
$request = Request::createFromGlobals();
var_dump($request->request->all());
此功能由AJAX发出。这可能是问题的原因吗?:
function sendMailAjax(form, method, url, outputElement){
let formData = new FormData(form);
$.ajax({
method: method,
url: url,
data: formData,
processData: false,
}).done(function (result) {
if(result.message === true) {
outputElement.css('color', 'green');
outputElement.text('Inviato');
}else {
outputElement.css('color', 'red');
outputElement.text('Errore');
}
});
}
答案 0 :(得分:1)
在您的AJAX通话中,更改
let formData = new FormData(form);
$.ajax({
method: method,
url: url,
data: formData,
收件人:
let formData = $("form").serialize();
$.ajax({
method: method,
url: url,
data: formData,