Add CORS for engines that support it
authorRichard Fairhurst <richard@systemeD.net>
Sat, 8 Mar 2014 14:03:08 +0000 (14:03 +0000)
committerRichard Fairhurst <richard@systemeD.net>
Sat, 8 Mar 2014 14:03:08 +0000 (14:03 +0000)
(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
app/assets/javascripts/routing_engines/mapquest.js
app/assets/javascripts/routing_engines/osrm.js

index 2a10a9d5e571cd8025ea30e6cfad0160af31bef5..204606005b2c1142f58f06cbb675b54ea2c93781 100644 (file)
@@ -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();
index f31a84458e43ef0c280d6f1dd105345061eab92f..598614c2977c1be80a0561f5658c5ec9eb2e1aa0 100644 (file)
@@ -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?
index 4122a0b4d73ecf52fbad0b1d1e4e2264a7796c54..fde871019917d671f699eb154619412dd74f191b 100644 (file)
@@ -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) {