【发布时间】:2020-05-24 07:02:03
【问题描述】:
在 Laravel 中,我有这个控制器:
public function getData()
{
$data = Bencana::all()->pluck('coord');
return response($data);
}
这是从我的数据库中加载数据的代码,我的 JS 看起来像这样:
$.ajax({
type : "POST",
url : '{{ route('getdata') }}',
headers : {'X-CSRF-TOKEN' : "{{ csrf_token() }}"},
dataType : 'json',
success : function(response) {
// console.log(response);
var layer = L.geoJson(response, {
style : myStyle
}).addTo(map);
}
});
该请求未在我的地图上显示圆、点、多边形数据。我被困在这里了。
谁能告诉我下一步该怎么做?
编辑:控制台没有错误,但我的数据库有不同的输出。
{ type : manythings, another :{}}
我将 json 类型的坐标保存到我的表中。当我尝试返回地图时,控制台显示:
{\type : \"somelikethat", \another :\"{}}
【问题讨论】:
-
你能试试
response.data吗? -
@Rolf OP 使用的是 jQuery,而不是 axios。
-
console.log(response)显示什么? -
啊啊好吧!好久没用jQuery了;)
-
您是否收到任何控制台错误?你确定
L和map在代码运行时已经正确设置了吗?
标签: javascript json laravel leaflet