-1

I am trying to develop a web using PlanGrid API, and i getting cross domain request block error.

var apiKey="API KEY";
var password="PASSWORD";
$.ajax({
    url: "https://io.plangrid.com/projects",
    xhrFields: {
        withCredentials: true
    },
    headers: {
        "Authorization": "Basic " + btoa(apiKey + ":" + password),
        Accept:'application/vnd.plangrid+json; version=1'
    },
    type: 'GET',
    crossDomain: true,
    success: function (data) {
        console.log(JSON.stringify(data));
    },
    error: function(data){
        console.log(JSON.stringify(data));
    }
});

After ajax request, i am getting error:

"Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 401."

Can someone let me know where i am going wrong. thanks

1 Answers1

0

Try changing https to http in ajax and see if it works. Match the protocol same as your domain that is localhost. Your localhost is on http.

Yuvraj Mudaliar
  • 375
  • 5
  • 15