none
XMLHttpRequest CORS errors RRS feed

  • Question

  • Hello,

    before yesterday, everything was fine with bing map.

    But after added the urlembed.com urlembed API to my project and that code below to make it works:

     (function() {
                  var cors_api_host = 'cors-anywhere.herokuapp.com';
                  var cors_api_url = 'https://' + cors_api_host + '/';
                  var slice = [].slice;
                  var origin = window.location.protocol + '//' + window.location.host;
                  var open = XMLHttpRequest.prototype.open;
                  XMLHttpRequest.prototype.open = function() {
                      var args = slice.call(arguments);
                      var targetOrigin = /^https?:\/\/([^\/]+)/i.exec(args[1]);
                      if (targetOrigin && targetOrigin[0].toLowerCase() !== origin &&
                          targetOrigin[1] !== cors_api_host) {
                          args[1] = cors_api_url + args[1];
                      }
                      return open.apply(this, args);
                  };
              })();

    The bing map API works but if I start typing the name of places(bing map AutoSuggest module), I have that error in my console:

    index.php:1 Access to XMLHttpRequest at 'https://cors-anywhere.herokuapp.com/https://www.bing.com/api/v6/Places/AutoSuggest?q=d&appid=F2DD9E3AA45F7512D9C6CA9A150CBA7F76556B81&mv8cid=62026f0c-d34f-9382-1e1e-d583d010a86e&mv8ig=5D045F6B1151422687660BC3B6DC0DB7&localMapView=&localcircularview=9.538000106811523,-13.677300453186035,100&count=3&structuredaddress=true&types=place,address&setmkt=en-WW&setlang=fr-FR&histcnt=&favcnt=&clientid=024D522BE7C869DF17285FE5E6C968C4' from origin 'http://localhost' has been blocked by CORS policy: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.

    How could i solve that problem to get the AutoSuggest results ?

    Thanks. 

    Saturday, September 7, 2019 3:26 PM