You may get a CORS error when accessing the API through your localhost. As an example :
$.ajax({ “async”: true, “crossDomain”: true, url: ‘https://stockvider.p.mashape.com/indicator/DATA/AAPL’, type: ‘GET’, data: {}, dataType: ‘json’, success: function (data) { console.dir((data.source)); }, error: function (err) { console.log(err); }, beforeSend: function (xhr) { xhr.setRequestHeader(‘X-Mashape-Key’, ‘XXX’); } });
Ariel
Doe mee aan de discussie - voeg hieronder een opmerking toe
CORS is fully enabled now. You no longer need to use JSONP.
Ariel
It seems that Mashape redirection is causing troubles but we are not 100% sure. However we can provide a workaround.
You can directly access our API while bypassing Mashape (http://api.stockvider.com/). Here is the correct Ajax request (the dataType has to be jsonp) :
$.ajax({ “async”: true,
“crossDomain”: true,
url: ‘http://api.stockvider.com/indicator/DATA/AAPL’,
type: ‘GET’,
data: {},
dataType: ‘jsonp’,
success: function (data) { console.dir((data.source)); },
error: function (err) { console.log(err); },
});
Ariel