If you take a look at the documentation, you will need to specify jsonp
as the parameter for jsonpCallbackParam
in order for Angular to use the correct request URL. This refers to the name of the GET parameter, not the callback function. Additionally, make sure to use route.json
instead of route.jsonp
.
$http.jsonp("http://www.distance24.org/route.json?stops="+city+"|"+country, {
jsonpCallbackParam: 'jsonp'
}).then(function(data) {
console.log(data);
alert(data.distance);
});
Another option is to do the following:
$http.jsonp("http://www.distance24.org/route.json", {
params: {stops: city+"|"+country},
jsonpCallbackParam: 'jsonp'
})
Prior to Angular v1.6, the jsonpCallbackParam
config value did not exist. Instead, you would utilize:
$http.jsonp("http://www.distance24.org/route.json?jsonp=JSON_CALLBACK&stops="+city+"|"+country)
or
$http.jsonp("http://www.distance24.org/route.json", {params: {
"stops": city+"|"+country,
"jsonp": "JSON_CALLBACK"
}})