Javascript openlayers3验证ol.format.GeoJSON上的url数据

Javascript openlayers3验证ol.format.GeoJSON上的url数据,javascript,ajax,openlayers-3,Javascript,Ajax,Openlayers 3,现在我有一个这样的层,可以正常工作: stations = new ol.layer.Vector({ name: 'stations', source: new ol.source.Vector({ format: new ol.format.GeoJSON(), url: Routing.generate('getData') }), style: styleFunction

现在我有一个这样的层,可以正常工作:

stations = new ol.layer.Vector({
        name: 'stations',
        source: new ol.source.Vector({
            format: new ol.format.GeoJSON(),
            url: Routing.generate('getData')
        }),
        style: styleFunction
    });
url返回有效的geojson数组

我想检查url是否返回数据或null以显示警报。现在,我正在用相同的请求执行上一个ajax调用,以检查它

$.ajax({ 
        type: "POST",
        url: Routing.generate('getData),
        dataType: "json",
        success: function (data) {
            for (var x in data) {
                if (x == "error") {
                    $("#error").html("<div class='alert alert-danger' style=\"margin-bottom: 0px; padding: 8px; height: 34px;\" role='alert'><span class='glyphicon glyphicon-exclamation-sign' aria-hidden='true'></span><span class='sr-only'>Error:</span>"+data[x]+"</div>");
                    $("#error").show();
                    map.removeLayer(stations);
                } else {
                    $("#error").hide();
                }
            }
        }
    });
我可以直接从ol3查这个吗


谢谢

如果您已经在进行前一个ajax调用,那么只需将数据geojson传递给ol.source.Vector即可。知道了?没有理由再打一次电话。当然可以,但我想在openlayer一侧检查一下。所以我不知道如何检查url参数是否返回数据或null。