How to fix “CORS problem: No ‘Access-Control-Allow-Origin’ Header is present on the requested resource.” [duplicate]


Ask A Question





Login To post a question

I have been trying to request data from google using the distance matrix but everytime I requested it throws up “Cross-Origin Request Blocked” using AJAX API.

Whenever I make use of PostMan it returns properly.

$.ajax({
     type: "GET",
     url: "https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=Obalende&destinations=Ikeja&mode=driving&departure_time=now&key=AIzaSyBTo0RgT_iA87Hd76gX8zYixB3PZh3z454",
     dataType: "json",
     crossDomain: true,
     cache: false,
     success: function(data){
     console.log(data);
  }
})

This is the error returned:

Access to XMLHttpRequest at ‘https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=Obalende&destinations=Ikeja&mode=driving&departure_time=now&key=AIzaSyBTo0RgT_iA87Hd76gX8zYixB3PZh3z454&_=1556004485228‘ from origin ‘https://danfobot.herokuapp.com‘ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

For more info please click herehttps://stackoverflow.com/q/55806284



Have a question or need a custom quote?
info@smartinfocare.com