0

I am using jQuery to call the AlphaVantage finance API for stock quotes in an HTML file on the local machine. However, the .get or .ajax calls are failing. I have tried using crossdomain and jsonp, but still the call fails in the error handler. The error text in the error handler is blank - so no indication is provided why it is failing. Any help would be appreciated. Here is the call:

$.ajax({
    url: 'https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=MSFT&apikey=demo', 
    crossDomain: true,
    dataType: "json",
    success: function(data, textStatus, jqXHR) {
        console.log(data);
    },
    error: function (jqXHR, textStatus, error) {
        console.log("Post error: " + error);
    }
});
  • See [Jquery load() only working in firefox?](https://stackoverflow.com/questions/32996001/jquery-load-only-working-in-firefox/), [Read local XML with JS](https://stackoverflow.com/questions/41279589/read-local-xml-with-js/) – guest271314 Sep 22 '17 at 05:12
  • Just remove ; at the end of the URL – Ramkee Sep 22 '17 at 05:35
  • That was a copy/paste error on my part when I was writing the question - removed the semi-colon, but that does not fix the problem - still get a blank error. – user8653303 Sep 22 '17 at 05:52

1 Answers1

0

You have a typo (the ';' after the url). Remove it and try again...

$.ajax({
    url: 'https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=MSFT&apikey=demo'**;**, 
    crossDomain: true,
    dataType: "json",
    success: function(data, textStatus, jqXHR) {
        console.log(data);
    },
    error: function (jqXHR, textStatus, error) {
        console.log("Post error: " + error);
    }
});
A. Iglesias
  • 2,625
  • 2
  • 8
  • 23
  • That was a copy/paste error on my part when I was writing the question - removed the semi-colon, but that does not fix the problem - still get a blank error. – user8653303 Sep 22 '17 at 05:53
  • I've realized you say that your using a local file (your code works perfectly in fiddle)! Looks like the browser security protection (doesn't allow that ajax calls by default if you're using a local file). Check the links @guest271314 has provided you – A. Iglesias Sep 22 '17 at 06:03