vendredi 5 août 2016

ajax call not allowed due to CORS

I'm trying to call github's endpoint to authorization but due to missing params or something related, I cannot.
this is my code to call

return new Ember.RSVP.Promise(function(resolve, reject){
  Ember.$.ajax({
    type: 'POST',
    // crossDomain: true,
    // xhrFields: {withCredentials: true},
    url: 'http://ift.tt/1j0ZcDZ',
    data: { 'code': code, 'client_id': 'token'  },
    dataType: 'json',
    beforeSend: function (xhr) {
      xhr.setRequestHeader("Accept", "application/json");
      xhr.setRequestHeader("Content-Type", "application/json");
      // xhr.setRequestHeader("Access-Control-Allow-Origin", "http://ift.tt/2aXzi95");
    },
    success: Ember.run.bind(null, resolve),
    error: Ember.run.bind(null, reject)
  });

when I do this, I get the error

XMLHttpRequest cannot load http://ift.tt/1j0ZcDZ. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:4200' is therefore not allowed access. The response had HTTP status code 404.

I also tried set the request header access-control-allow-origin to the exact URl in my oauth app and also didn't worked




Aucun commentaire:

Enregistrer un commentaire