ipify-api icon indicating copy to clipboard operation
ipify-api copied to clipboard

{"ip": "<nil>"} returned when supplying callback parameter

Open ByteJuggler opened this issue 8 years ago • 2 comments

Hi,

When I hit the service with say https://api.ipify.org/?format=jsonp

I get back as expected: callback({"ip":"195.xxx.xxx.xxx"});

However if I add the "callback" parameter, for example http://api.ipify.org/?format=jsonp&callback=jq

...then I get back: jq({"ip":"\u003cnil\u003e"});

Why? Is this a bug?

ByteJuggler avatar Sep 05 '17 09:09 ByteJuggler

I'm now trying to call it directly from script code with jQuery:

$.getJSON('//api.ipify.org?format=json', function(data) {
  console.log("data: " + data);
  console.log(JSON.stringify(data, null, 2));
});

This results in (in the console):

data: [object Object]
VM2301:8 {
  "ip": "<nil>"
}

Is this somehow something I'm doing wrong?

ByteJuggler avatar Sep 05 '17 09:09 ByteJuggler

I have now tried another service that seems to work correctly, which suggests this must be a bug perhaps. The following code works:

$.getJSON('//jsonip.com', function(data) {
  x=document.getElementById("myDiv");
  x.innerHTML = "Your IP is: <b>" + data.ip + "</b>";
  console.log("IP: " + data.ip);
});

This results as expected in the console in: IP: 195.xxx.xxx.xxx

ByteJuggler avatar Sep 05 '17 10:09 ByteJuggler