我正在尝试进行两次依赖选择,但无法获得ajax调用以使其正常工作。 我的ajax电话是:
var data = {
tower_id:$(this).val();
};
$.ajax({
type: "POST",
url: "{{ path('select_apartment')}}",
data:data,
success: function(data) {
var $apartment_selector = $('#apartamentos_apartamentosbundle_resident_apartmentid');
$apartment_selector.html('<option>Apartamentos</option>');
for (var i=0, total = data.length; i < total; i++) {
$apartment_selector.append('<option value="' + data[i].id + '">' + data[i].number + '</option>');
}
}
});
控制器中的方法是:
public function ApartmentsAction(Request $request){
$tower_id = $request->request->get('tower_id');
$em = $this->getDoctrine()->getManager();
$apartments = $em->getRepository('ApartamentosApartamentosBundle:Apartment')->findByTowerId($tower_id);
return new JsonResponse($apartments);}
好像javascript没有调用该方法。方法的路线是:
*@Route("/residentapt", name="select_apartment")
我做错了什么?任何想法?
谢谢。