From 2f0794738c022f060a07d45f6bed3ea68ea4d166 Mon Sep 17 00:00:00 2001 From: Richard Fairhurst Date: Sat, 8 Mar 2014 14:03:08 +0000 Subject: [PATCH] Add CORS for engines that support it (Do we need a fix for IE8/9? - https://github.com/MoonScript/jQuery-ajaxTransport-XDomainRequest - https://github.com/jaubourg/ajaxHooks/blob/master/src/xdr.js ) --- app/assets/javascripts/routing.js.erb | 3 +++ app/assets/javascripts/routing_engines/mapquest.js | 2 +- app/assets/javascripts/routing_engines/osrm.js | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/routing.js.erb b/app/assets/javascripts/routing.js.erb index 2a10a9d5e..204606005 100644 --- a/app/assets/javascripts/routing.js.erb +++ b/app/assets/javascripts/routing.js.erb @@ -248,6 +248,9 @@ OSM.Routing=function(map,name,jqSearch) { script.src = url+r.name+".gotRoute"+num; document.body.appendChild(script); }; + list[num].requestCORS=function(url) { + $.ajax({ url: url, method: "GET", data: {}, dataType: 'json', success: r['gotRoute'+num] }); + }; r['gotRoute'+num]=function(data) { r.awaitingRoute=false; $(".query_wrapper.routing .spinner").hide(); diff --git a/app/assets/javascripts/routing_engines/mapquest.js b/app/assets/javascripts/routing_engines/mapquest.js index f31a84458..598614c29 100644 --- a/app/assets/javascripts/routing_engines/mapquest.js +++ b/app/assets/javascripts/routing_engines/mapquest.js @@ -48,7 +48,7 @@ MapQuestEngine.prototype.createConfig = function() { //url+="&locale=" + I18n.currentLocale(); //Doesn't actually work. MapQuest requires full locale e.g. "de_DE", but I18n only provides language, e.g. "de" url+="&manMaps=false"; url+="&shapeFormat=raw&generalize=0"; - this.requestJSONP(url+"&callback="); + this.requestCORS(url); }, gotRoute: function(router,data) { // *** what if no route? diff --git a/app/assets/javascripts/routing_engines/osrm.js b/app/assets/javascripts/routing_engines/osrm.js index 4122a0b4d..fde871019 100644 --- a/app/assets/javascripts/routing_engines/osrm.js +++ b/app/assets/javascripts/routing_engines/osrm.js @@ -24,7 +24,7 @@ OSRMEngine.prototype.createConfig = function() { if (this._hints[pair]) url+= "&hint="+this._hints[pair]; } if (isFinal) url+="&instructions=true"; - this.requestJSONP(url+"&jsonp="); + this.requestCORS(url); }, gotRoute: function(router,data) { if (data.status==207) { -- 2.39.5