0

I'm trying to make an API post call using jquery $.ajax but i'm getting the following error

Failed to load https://accounts.spotify.com/api/token: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://sontest.000webhostapp.com' is therefore not allowed access.

any help would be appreciated.

$.ajax(
      'https://accounts.spotify.com/api/token', {
      type: 'POST',
      headers: {
                "Access-Control-Allow-Origin": "*",
                "Access-Control-Allow-Methods": "GET, POST, OPTIONS",
                "Access-Control-Allow-Headers": "X-Requested-With,content-type",
                "Access-Control-Allow-Credentials": false
               },
               dataType: 'json',
               beforeSend: function (xhr) {
                  xhr.setRequestHeader('Authorization', 'Basic ' + spotifyDetails);
                  xhr.setRequestHeader("content-type", "application/x-www-form-urlencoded");
               },
               data: "grant_type=client_credentials",
               complete: function (response) {
               },
               error: function (jqXHR, textStatus, errorThrown) {
                 console.log(errorThrown);
               }
});
akano1
  • 40,596
  • 19
  • 54
  • 67

0 Answers0