1
這是我的控制器:我想通過ID的數組路線的Symfony
/**
* @Route("/order", name="finish")
*/
public function createAction(Request $request)
{
$form = $this->createForm(OrderType::class);
// get data using the ids pass to the request...
// handle the form and redirect to homepage
return $this->render(
"orders/order_view.html.twig",
['order'=>$form->createView()]
);
}
我想一些標識傳遞到請求,以便我能學說得到所需要的數據。 之後,處理表單創建新的訂單,並添加到我已經有了產品感謝ID通過。
我試圖通過使用按鈕單擊ajax的ID:
$.ajax(
{
type: 'POST',
url: '/order',
data: {'arr':[2,3,4]} // sample ids
}
).done(function (data) {
console.log(data)
}).fail(function() {
console.log("some error")
})
,但它只是返回的HTML。我需要的是呈現在指定的路線(「/訂單」)的形式,所以我可以處理它,並插入到數據庫中的新訂單與產品添加到它
我認爲你可以得到你阿賈克斯使用數據$請求 - >的getContent() –