cross-domain data with AJAX using JSONP
Posted
by
kooshka
on Stack Overflow
See other posts from Stack Overflow
or by kooshka
Published on 2012-11-17T10:56:26Z
Indexed on
2012/11/17
11:01 UTC
Read the original article
Hit count: 256
I'm trying to get data from Geobytes. One of the templates returns JSON and I need to cross-domain access it.
I wrote these 2 functions
function getCountry(ip) {
var surl = "http://www.geobytes.com/IpLocator.htm?GetLocation&template=json.txt";
$.ajax({
url: surl,
data: '{"ipaddress":"' + ip + '"}',
dataType: "jsonp",
jsonp: "callback",
jsonpCallback: "jsonpcallback"
});
}
function jsonpcallback(rtndata) {
alert(rtndata.message);
}
The call is executed but I get
- 1 warning: Resource interpreted as Script but transferred with MIME type text/html: "http://www.geobytes.com/IpLocator.htm?GetLocation&template=json.txt&callback=jsonpcallback&{%22ipaddress%22:%22200.167.254.166%22}&_=1353148931121"
- 1 Error: Uncaught SyntaxError: Unexpected token :
The error is thrown on the returned data at
{"geobytes":{"countryid":117,
I think is maybe because it's 117 and not "117" but I obviously can't control the returned data
How can I fix these 2 issues?
© Stack Overflow or respective owner