ajax - display a json response -


i have json when sending json post request , fetching return data

 $.post("/employees", {id:"3"}, function(response){     if(response.success)     {         var branchname = $('#branchname').empty();         console.log(response.employees);         $.each(response.employees, function(user_no, firstname, lastname){             $('<option/>', {                 value:user_no,                 text: firstname + " " + lastname             }).appendto(branchname);         });     } }, 'json');  

and in controller, gets id , find record/records $branch_no equal $id , column user_no, firstname , lastname , return json response.

public function getemployee(){     $id = $_post['id'];     $employees = mot_users::where("branch_no", $id)     ->select(array('user_no', 'lastname', 'firstname'))     ->get()->toarray();     return response()->json(['success' => true, 'employees' => $employees]); } 

now supposed display response as

<select>     <option value="1">firstname lastname</option>     <option value="2">firstname lastname</option>     <option value="3">firstname lastname</option>     <option value="4">firstname lastname</option> </select> 

but display as

<select>     <option value="0">[object object]</option>     <option value="1">[object object]</option>     <option value="2">[object object]</option>     <option value="3">[object object]</option> </select> 

i got no error in console , think fetch json response incorrectly ideas, help, clues, suggestions, recommendations make work?

try this

$.post("/employees", {id:"3"}, function(response){     if(response.success)     {         var branchname = $('#branchname').empty();         console.log(response.employees);         $.each(response.employees, function(index, value){             $('<option/>', {                 value:user_no,                 text: value.firstname + " " + value.lastname             }).appendto(branchname);         });     } }, 'json');  

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -