我卡在这里,已经尝试了其他解决方案,但没有希望。我按照here中的示例进行操作,并生成此代码:
<head>
<script>
var xmlhttp = new XMLHttpRequest();
var url = "{{ url('sogi') }}";
var myArr;
var out = "";
var i;
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
myArr = JSON.parse(xmlhttp.responseText);
for(i = 0; i < myArr.length; i++) {
out += myArr[i].testing1 + myArr[i].testing2 + '<br>';
}
document.getElementById("allit").innerHTML = out;
alert(out);
}
};
xmlhttp.open("GET", url, true);
xmlhttp.send();
</script></head>
<body>
<div id="allit"></div>
</body>
Route :: get('sogi','Sig @ testing');
sig控制器(案例1):
public function testing()
{
$response = array('testing1' =>'success','testing2' => 'failed');
return response()->json($response);
}
sig控制器(案例2):
public function testing($route)
{
$check = Jalan::where('a', '=', $route)->toArray();
return response()->json($check);
}
但是结果总是空白,即使警告框显示为空白,如果使用雄辩的话,如何从像上面的控制器(案例1)和(案例2)的laravel单个数组获得JSON响应?
答案 0 :(得分:0)
解决了,在多个查询中出错,应该是这样的:
public function testing($route)
{
$check = Jalan::where('a', 'LIKE', '%'.$route.'%')->toArray();
return response()->json($check);
}