我得到 Uncaught TypeError: "Cannot read property '0' of undefined" 错误。我就是想不通这个问题。
尽管程序运行良好,但我得到了所需的输出。但是错误...
$(window).bind("load", function() {
var ws = new WebSocket("wss://www.bitmex.com/realtime?subscribe=trade:XBTUSD");
ws.onopen = function(){
ws.send(JSON.stringify({"trade":"XBTUSD"}))
};
ws.onmessage = function (msg){
var resp = JSON.parse(msg.data);
console.log(resp);
var price = resp['data'][0].price; // can not read property 0 of undefined :/
console.log('Price is : ' + price);
};
});