I'm trying to retrieve stock data using Yahoo's Finance API:
$.ajax({
dataType: "json",
url: 'http://download.finance.yahoo.com/d/quotes.csv',
data: 's=RHT+MSFT&f=sb2b3jk&callback=?',
success: function (d) {
console.log(JSON.stringify(d));
},
error: function (d, a, b) {
console.log(JSON.stringify(d));
console.log(JSON.stringify(a));
console.log(JSON.stringify(b));
},
complete: function (d, a, b) {
console.log(JSON.stringify(d));
console.log(JSON.stringify(a));
console.log(JSON.stringify(b));
}
});
The call works and I can see the csv text in the response (using Chrome's developer tools):

Now, my problem is I can't access the text contained in the response.
As you can see in the original script, I've tried capturing the responses in the "success", "error", and "complete" callbacks, but the response text is not contained in any of them. Also, only the "error" and "complete" callback is raised.
I'd appreciate any insight on this, thanks in advance!
ps. Reason I'm using the CSV query, as opposed to the YQL query is the CSV query is easier to specify fields I need. I've found the YQL query much more cumbersome to use.
The $.getJSON() method accepts text/json content types and the CSV is not of this type.
This is a shorthand Ajax function, which is equivalent to:
$.ajax({ dataType: "json", url: url, data: data, success: success });
The complete executes because it executes regardless of whether the request resulted in a success or error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With