2017-07-27 190 views
-6

我正在做一個簡單的jquery ajax調用該URL,如下所示。響應是OK 200,我正在嘗試console.log responseText,但我什麼都沒有收到。我究竟做錯了什麼?jQuery Ajax響應200,但無法訪問響應數據

而我該如何在沒有jQuery的純JavaScript中做到這一點?

$.ajax({ 
    url:'https://poloniex.com/private.php?currencyPair=BTC_LTC&rate=0.016&amount=1&command=buy', 
    dataType:'json', 
    success: function(data, textStatus, xhr){ 
console.log('asdfasdfadsf');  
console.log(data); 
    console.log('hello' + textStatus); 
    console.log(xhr.responseText); 

    }//success 

}); //ajax 

enter image description here

+1

那你記錄'data'然後試着訪問'xhr.responseText' – tymeJV

+0

我怎麼看它:創建ajax.html +粘貼responseText那裏 - 9/10它會顯示一個錯誤 – ThisGuyHasTwoThumbs

+1

你已經設置了'dataType :'json',但這很明顯是HTML。 –

回答

0

因爲你解析響應作爲JSON字符串和Ajax您重定向到一個「錯誤」回調。將dataType更改爲html,或更改腳本的回覆。

+1

感謝您解決我的問題。我可以看到爲什麼stackoverflow正在下山,這是因爲在這裏只是恐嚇任何新手張貼的大量的自負巨魔。我有一個不正確的值設置爲「JSON」,當它應該是HTML。 –