【发布时间】:2017-06-08 15:31:27
【问题描述】:
我正在尝试从 Laravel 5 上的 API 获取 JSON 数据,路线给了我正确的 浏览器中的数据,但尝试在 JQuery 中访问此路由时失败。 路线是: http://localhost:8000/search/student/all
终于在浏览器中工作了,数据以json格式显示 但是这个脚本失败了:
$(document).ready(function(){
$("button").click(function(){
$.getJSON("http://localhost:8000/search/student/all", function(result){
$.each(result, function(i, field){
$("div").append(field + " ");
});
});
});
});
我将 localhost:8000 替换为 127.0.0.1:8000 但没有任何改变。
注意:我使用 Laravel 生成了 json 响应
$students=App\Student::all();
return response()->json($students);
【问题讨论】:
标签: php jquery json laravel-5 csrf