0

My code is this:

var username = "john";
var password = "doe";

var url = '//api.bos2.cf/?type=verify&username=' + username + '&password=' + 
password + '&callback=?';
$.getJSON(url, function(data) {
  success: readData(data)
});

function readData(data) {
  alert(data);
}

Although this code alerts object Object instead of {'success' : false, 'msg' : 'Unknown API function'}

Any Ideas as to why this is happening??

Thanks,

CSF

csf30816
  • 131
  • 3
  • 11

2 Answers2

1

You are trying to display the raw object. You need to turn it into a string first:

function readData(data) {
  alert(JSON.stringify(data));
}
Imanuel
  • 3,596
  • 4
  • 24
  • 46
  • Thanks! Is there anyway to retrieve the value of "success" that you know of? – csf30816 Apr 21 '17 at 07:06
  • If it is part of the object `data`, it is part of the alert text. If you only want to access the field `success`, use `data.success`. Beware that this is a `boolean`, not a `string`. – Imanuel Apr 21 '17 at 07:11
  • OK thanks. I am aware, I just might need that in the future. – csf30816 Apr 21 '17 at 07:13
0
function readData(data) {
  alert(data.success);
  alert(data.msg);
}

just go through simple way.

Ahmed Ginani
  • 6,522
  • 2
  • 15
  • 33