eriklane
eriklane

Reputation: 143

HostIP.info get_json not calling jQuery ajax callback

I'm just trying to get a user's IP address via jQuery/JSONP and had success with other services but I cannot determine why the callback is not called when using hostip.info's JSON API

Firebug and Fiddler both show the JSON response data I am expecting but success is never called and the error is a parse error so I must be missing something.

Any thoughts or suggestions would be great. Thanks in advance.

jsFiddle example

Simple code:

$.ajax({
    type: "GET",
    url: "http://api.hostip.info/get_json.php",
    dataType: "jsonp",
    success: function(json) {
        alert(json.ip);
    },
    error: function (request, type, status)
    {
       alert('[request: ' + request.statusText + '] [type: ' + type + '] [status: ' + status + ']');
     }
});

Upvotes: 1

Views: 536

Answers (1)

Musa
Musa

Reputation: 97717

The service is json not jsonp, change dataType to json, see http://jsfiddle.net/wdqeV/3/

Upvotes: 3

Related Questions