Ajaxでフォームを投稿しています。
Ajax呼び出し内でフォームをバインドすると、驚くべき応答があります。
public function newCartAjaxAction(Request $request)
{
$form = $this->container->get('new_cart_form.factory')->create();
$formHandler = $this->container->get('new_cart_form.handler');
if ('POST' === $request->getMethod())
{
$form->bind($request);
if ($form->isValid())
{
$formHandler->processValidForm($form);
$response = new Response();
$response->headers->set('Content-type', 'application/json; charset=utf-8');
$response->setContent(json_encode('hello'));
return $response;
}
//...
}
//....
}
ファイヤーバグを使用して、驚くべきことにajaxレスポンスで3つの出力を取得します。
array(2) {[0]=>int(3)[1]=>int(5)} //unexpected response
int(3) //unexpected response
"hello" //The only response needed
デバッグした後、出力1と2がからのものであることがわかりました$form->bind($request);
誰かがそれがなぜであるか知っていますか?私が送信することになっている唯一の応答は$responseであるため、フォームバインディングステップから応答を取得することに非常に驚いています...
私は何か間違ったことをした?