【发布时间】:2019-11-13 14:20:16
【问题描述】:
这是我的控制器:
public function updateCustomerRecord(Request $request)
{
$datda = $request->all(); // This will get all the equest data.
$teste = "teste";
$selectt = DB::select('select * from users');
return response()->json(['success' => true, 'teste' => $teste, 'selectt' => $selectt]);
}
这是我在视图上的 ajax:
$(document).ready(function(){
$('#getRequest').click(function(){
$.ajax({
method: 'POST', // Type of response and matches what we said in the route
url: '/customer/ajaxupdate', // This is the url we gave in the route
data: {'id' : id}, // a JSON object to send back
success: function(response){ // What to do if we succeed
var theDiv = document.getElementById("teste");theDiv.innerHTML = response.selectt[1].;
console.log(response);
},
error: function(jqXHR, textStatus, errorThrown) { // What to do if we fail
console.log(JSON.stringify(jqXHR));
console.log("AJAX error: " + textStatus + ' : ' + errorThrown);
}
});
})
})
通过 console.log 我得到以下数据:
我希望做一个 foreach 并回显整个数组。
【问题讨论】:
-
这里有什么问题?
-
对不起,我没有关注。您想单独打印整个数组,包括子元素吗?打印 selectt 的内容?
-
是的,我想单独打印包含子元素的数组。 @Kurisu