How to get a cross-origin resource sharing (CORS) post request working

后端 未结 11 2374
野趣味
野趣味 2020-11-21 22:35

I have a machine on my local lan (machineA) that has two web servers. The first is the in-built one in XBMC (on port 8080) and displays our library. The second server is a

11条回答
  •  滥情空心
    2020-11-21 23:31

    I solved my own problem when using google distance matrix API by setting my request header with Jquery ajax. take a look below.

    var settings = {
              'cache': false,
              'dataType': "jsonp",
              "async": true,
              "crossDomain": true,
              "url": "https://maps.googleapis.com/maps/api/distancematrix/json?units=metric&origins=place_id:"+me.originPlaceId+"&destinations=place_id:"+me.destinationPlaceId+"®ion=ng&units=metric&key=mykey",
              "method": "GET",
              "headers": {
                  "accept": "application/json",
                  "Access-Control-Allow-Origin":"*"
              }
          }
    
          $.ajax(settings).done(function (response) {
              console.log(response);
    
          });
    

    Note what i added at the settings
    **

    "headers": {
              "accept": "application/json",
              "Access-Control-Allow-Origin":"*"
          }
    

    **
    I hope this helps.

提交回复
热议问题