我試圖使用雅虎財經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));
}
});
呼叫的作品,我可以看到在響應中的CSV文本(使用Chrome的開發者工具) :
現在,我的問題是我無法訪問包含在響應中的文本。
正如你可以在原來的劇本看,我試圖捕捉在"success"
,"error"
和"complete"
回調的響應,但響應文本不包含在其中任何一個。此外,僅引發"error"
和"complete"
回調。
我希望對此有所瞭解,提前致謝!
ps。原因我正在使用CSV查詢,而不是YQL查詢,因爲CSV查詢更容易指定我需要的字段。我發現YQL查詢使用起來更麻煩。
CSV不是JSON。顧名思義,'$ .getJSON'就是JSON的**。**爲什麼'$ .getJSON'不能很好地與CSV一起玩呢? – 2013-02-12 20:57:02
附註:使用'console.log()'http://stackoverflow.com/questions/4743730/what-is-console-log-and-how-do-i-use-it – Dom 2013-02-12 20:58:02
看看[this答案](http://stackoverflow.com/a/12785546/551322)。它可以幫助你。 – nrodic 2013-02-12 21:11:15