php - Jquery AJAX Post: 500 (Internal Server Error)? in Symfony 3 -


i trying post id controller action getting error : (i using symfony 3).

jquery-1.11.0.min.js:4 post http://localhost/plate/web/app_dev.php/province_ajax_call?province_id=2 500 (internal server error)

here ajax code :

 <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> {{ form(form_account) }}   <script> $(document).ready(function(){     $('#appbundle_account_province').change(function(){         var val = $('#appbundle_account_province').val();         $.ajax({             type: "post",             url: "{{ url('province_ajax_call') }}?province_id=" + val,             success: function(data){                 $('#appbundle_account_city').html('');                 $.each(data, function(key, value){                     $('#appbundle_account_city').append('<option value="'+ key +'">'+ value +'</option>');                })                console.log('succes');             }         })     }) }) 

here controller code :

public function provinceajaxcallaction(request $request) {      if (!$request->isxmlhttprequest())     {         throw new notfoundhttpexception();     }      $id = $request->query->get('province_id');     var_dump($id);      $cities = $this               ->getdoctrine()               ->getmanager()               ->getrepository('appbundle:city')               ->findbyprovinceid($id);      $result = array();     foreach($cities $city){         $result[$city->getid()] = $city->getname();     }     return new jsonresponse($result); }  public function indexaction(request $request) {     $account = new account();      $form = $this->createform(accounttype::class, $account);     $form->handlerequest($request);      if($form->isvalid())     {         $this->getdoctrine()->getmanager()->persist($account);         $this->getdoctrine()->getmanager()->flush();          return $this->redirecttoroute('test_registration_homepage');     }      return $this->render('default/index.html.twig', array('form_account' => $form->createview()));   } } 

i resolved problem adding

use symfony\component\httpfoundation\jsonresponse; 

in controller.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -