-5

I'm doing a simple jquery ajax call to the url as seen below. The response is OK 200 and I'm trying to console.log the responseText, but I'm getting nothing. What am I doing wrong?

And how would I do this in pure javascript without jQuery?

$.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

Patoshi パトシ
  • 21,707
  • 5
  • 29
  • 47
  • 1
    Well you log `data` then try and access `xhr.responseText` – tymeJV Jul 27 '17 at 15:51
  • how I view it: create ajax.html + paste the responseText there - 9/10 it'll show an error – treyBake Jul 27 '17 at 15:52
  • 1
    You've set `dataType: 'json'`, yet that is clearly HTML. – Rory McCrossan Jul 27 '17 at 15:52
  • haha. because it doesn't exist yet. – Kevin B Jul 27 '17 at 15:52
  • Possible duplicate of [how do I get the reponse text from ajax / jquery?](https://stackoverflow.com/questions/5366900/how-do-i-get-the-reponse-text-from-ajax-jquery) – Namaskar Jul 27 '17 at 15:53
  • yeah no not a dupe of that. it's a dupe of how do i do error handling – Kevin B Jul 27 '17 at 15:54
  • 1
    For having 2000+ rep, you sure ask a question terribly .. No editable code .. Just an image? ... Odd if you ask me. – Zak Jul 27 '17 at 15:57
  • i wanted to give an idea of what the output was in the console. which is why i took a snapshot. this is why stack overflow is going down hill due to the amount of trolling newbies get posting something they aren't familiar with. everyone started somewhere, even you. – Patoshi パトシ Jul 27 '17 at 17:17
  • Why edit the question with the answer? Seeing the accepted answer tell you to change `dataType` to html, and it already is in your code, doesn't make sense. – Namaskar Jul 28 '17 at 12:04

1 Answers1

1

Because you are parsing the response as a json string, and ajax redirect you to an "error" callback. Change dataType to html, or change the reply of your script.

Ryosaku
  • 453
  • 4
  • 14
  • 2
    Thanks for solving my problem. I can see why stackoverflow is going down hill due to the the amount of egotistical trolls on here that just scare off any newbies posting. I had an incorrect value set to "json", when it should be html. – Patoshi パトシ Jul 27 '17 at 17:14