ajax - How to work around the CORS issue in Surface API from mapbox? -
i trying use surface api mapbox analyze terrain between 2 given points. taking coordinates of 2 points , sending ajax call api stuck infamous cors issue.
to start trying use url provided mapbox in examples:
$('#runterrainanalysis').on('click', function(e){ var url = 'https://api.tiles.mapbox.com/v4/surface/mapbox.mapbox-terrain-v1.json?layer=contour&fields=ele&points=-112.084004,36.05322;-112.083914,36.053573;-112.083965,36.053845&access_token=pk.eyj1ijoicm9oyw4wnzkziiwiysi6ijhfegvzvzgifq.mqbzohjmjh19bxdw0b8nkq'; $.ajax({ url: url, method: 'get', success: function(response){ console.log(response); }, error: function(response){ console.log(response); } }); });
cross-origin request blocked: same origin policy disallows reading remote resource @ https://api.tiles.mapbox.com/v4/surface/mapbox.mapbox-terrain-v1.json?layer=contour&fields=ele&points=-112.084004,36.05322;-112.083914,36.053573;-112.083965,36.053845&access_token=pk.eyj1ijoicm9oyw4wnzkziiwiysi6ijhfegvzvzgifq.mqbzohjmjh19bxdw0b8nkq. (reason: cors header 'access-control-allow-origin' missing).
how work?
mapbox api supports cross-origin requests no domain restrictions, must related jquery.
try include crossdomain: true
:
$.ajax({ url: url, crossdomain: true, method: 'get',
Comments
Post a Comment