samedi 25 février 2017

Getting {"readyState":0,"status":0,"statusText":"error"} when making a JSON request to a different url

I am attempting to make a JSON request to an API located on a different url using ember-simple-auth and a custom adapter. When I make the request and check the the console the request returns Status code: 301 Moved Permanently and I am returned the error {"readyState":0,"status":0,"statusText":"error"}

import Base from 'ember-simple-auth/authenticators/base';

const { RSVP: { Promise }, $: { ajax }, run } = Ember;

export default Base.extend({
  restore(data) {

  },

  authenticate(credentials) {

    const { identification, password } = credentials;

const data = JSON.stringify({
  name: identification,
  password: password,
  secret: '012345'
});

const requestOptions = {
  async: true,
  crossDomain: true,
  url: 'http://ift.tt/2mja9LE',
  processData: false,
  method: 'POST',
  contentType: 'application/json',
  data: data,
};

console.log(JSON.stringify(requestOptions));
console.log(data);

return new Promise((resolve, reject) => {
  ajax(requestOptions).then((response) => {
    const { jwt } = response;
    run(() => {
      resolve(
        // response
        {token: jwt}
      );
    });
  }, (error) => {
    run(() => {
      reject(error);
    });
  });
});
  },

  invalidate(data) {
  }
});

When I print the requestOptions variable I get {"async":true,"crossDomain":true,"url":"http://ift.tt/2mja9LE","processData":false,"method":"POST","contentType":"application/json","data":"{\"name\":\"foo\",\"password\":\"bar\",\"secret\":\"012345\"}"}

I'm not sure what the issue is, any help is appreciated.




Aucun commentaire:

Enregistrer un commentaire