我正在尝试通过AJAX将数据发送到我的Symfony控制器路由。现在,我只是对一些东西(数据和动态URL)进行硬编码。
$('#add_assistant_next').click(function () {
console.log('pressed');
var that = $(this);
$.ajax({
url: '/courseSpace/20866/listAssistantEnrollment',
type: "POST",
dataType: "json",
data: {"ajax-user": "test user string"},
async: true,
success: function (data) {
console.log(data);
$('div#ajax-results').html(data.output);
}
});
return false;
});
控制器
/**
* @Route(name="list_assistant_enrollment", methods={"GET", "POST"}, path="/courseSpace/{courseSpaceId}/listAssistantEnrollment")
*
* @ParamConverter("courseSpace", class="AppBundle\Entity\CourseSpace")
* @ParamConverter("listSettings", class="AppBundle\View\ListEnrollment\ListSettings", options={"activeTab" = ListSettings::ASSISTANT_TAB})
*
* @param Request $request
* @param ListSettings $listSettings
* @param CourseSpace $courseSpace
*
* @return Response
*/
public function assistantEnrollmentAction(Request $request, ListSettings $listSettings, CourseSpace $courseSpace)
{
if ($request->isXmlHttpRequest()) {
dump('request received');
die();
}
if ($request->request->get('ajax-user')) {
dump('request received');
die();
}
}
我相信请求已正确发送,但是我无法在控制器端处理它。我一直收到404错误,直到我为该路由硬编码了一些有效的courseSpaceId
参数