returning DB data via ajax json -


I am posting data to an administrator via Ajax (selected) and want to return some database Jason-data . When I return only the data sent (selected), it all works well, but as soon as I want to return the DB data I have a server 500 error (the supernatural model is definitely present and the second in the same class Function works) Thanks for any indication!

Ajax call:

  $ ('# country'). ('Change', function () {var selected = $ ('# country'). Val (); $ .ajax ({url: "inputChange", type: 'post', data: {selected: selected}, data Type: 'json'}). (Function (data) {console log (data.name_en);});}); Root:  
 
  Root :: Anyone ('InputChange', array ('as' = 'InputChange', 'Use' = & gt; 'UserController @ inputChange'));  

Controller (working without DB data):

  public function inputChange () {$ select = input :: get ('selected'); Return Feedback: Jason ($ selected);  

The controller (DB is not working with data - Error 500 - which is without segment for the $ selected below):

  Public function inputChange () {$ selected = input :: get ('selected'); $ Data = city :: all () - & gt; get receive (); Return Feedback: Jason ($ data); }  

You do not want get () city data When doing all , your code should be:

  Change public function input () {$ selected = input :: get ('selected') ; $ Data = city :: all (); Return Feedback: Jason ($ data); }  

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -