How to solve "Uncaught SyntaxError: Unexpected token <" error

How to solve "Uncaught SyntaxError: Unexpected token <" error

我正在开发 openlayers 3,我正在尝试执行这个简单的 JavaScript 函数:

function mapScript() {
    // create a vector source that loads a GeoJSON file
    var vectorSource = new ol.source.Vector({
        projection: 'EPSG:3857',
        format: new ol.format.GeoJSON(),
        url: 'countries.geojson'
    });

    // a vector layer to render the source
    var vectorLayer = new ol.layer.Vector({
        source: vectorSource
    });

    var center = ol.proj.transform([0, 0], 'EPSG:4326', 'EPSG:3857');

    var view = new ol.View({
        center: center,
        zoom: 1
    });

    // the vector layer gets added like a raster layer
    var map = new ol.Map({
        target: 'map',
        layers: [vectorLayer],
        view: view
    });
} // END of mapScript()

我见过很多类似的问题,但这些解决方案都不适用于我的情况。我是 openlayers 的新手,所以请任何人指导我解决这个问题。

提前感谢您的时间。

更新:

我浏览器的 "Network" 栏向我显示:

"countries.geojson"的来源是这样的:

https://github.com/openlayers/ol3/blob/master/examples/data/geojson/countries.geojson

我下载了这个文件,现在它在我的本地目录中。我认为我项目中的这种文件链接导致了问题。任何人都可以帮助我正确使用这个文件吗?

https://github.com/openlayers/ol3/blob/master/examples/data/geojson/countries.geojson is not a GeoJSON document, it's a HTML page on github about the GeoJSON document in the repo. The actual GeoJSON data can be found by clicking the "Raw" link on that page: https://raw.githubusercontent.com/openlayers/ol3/master/examples/data/geojson/countries.geojson