Reputation: 169
I asked a similar question to this earlier but perhaps this is a bit more clear.
I am trying to retrieve json data from the OSRM routing server (API here: https://github.com/DennisOSRM/Project-OSRM/wiki/Server-api).
I am currently using this code:
$(function () {
$("#getJSON").click(function () {
var url = "http://router.project-osrm.org/viaroute?loc=51.500,0.100&loc=51.500,0.1001&jsonp=myroute";
$.ajax({
dataType: "json",
url: url,
jsonpCallback: 'myroute',
success: function (data) {
test = data.route_geometry;
alert(test);
}
});
});
});
However I don't get any response from this. Eveidently something is wrong, although I've tried it removing the callbacks and 'jsonp=myroute' part with no success either.
Thanks for any help.
Nick
Upvotes: 2
Views: 1890
Reputation: 8407
Finally, i got this working
$(function () {
var url = "http://router.project-osrm.org/viaroute?loc=51.500,0.100&loc=51.500,0.1001";
$.ajax(url, {dataType:"jsonp", jsonp:"jsonp", cache:true}).success(function() {
console.log(arguments);
});
});
if you put the url into the browser, which gets generated by jquery, then you see a 400 error, as jquery adds the "&=[TIMESTAMP]" param. But your remote server says, the url is then malformed. If you give jquery the "cache" option with a true value, it will not append the "" parameter.
If you have further issues, try to replace the "success" with the "always" callback, as you will then be notified every time the callback succeds or not. Because sometimes there is an error within jquery, which you wouldnt notice in developer tools
Upvotes: 1