Ajax 显示json响应
我在发送json post请求和获取返回数据时使用了这个jsonAjax 显示json响应,ajax,json,laravel,laravel-5,Ajax,Json,Laravel,Laravel 5,我在发送json post请求和获取返回数据时使用了这个json $.post("/employees", {id:"3"}, function(response){ if(response.success) { var branchName = $('#branchname').empty(); console.log(response.employees); $.each(response.employees, functio
$.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');
现在它应该将响应显示为
<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>
但它显示为
<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>
我的控制台中没有错误,我想我获取的json响应不正确,所以有什么想法、帮助、线索、建议和建议可以让这项工作正常进行吗?试试这个
$.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');
$.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');