A
A
Alexey Aristov2016-06-21 16:52:53
JavaScript
Alexey Aristov, 2016-06-21 16:52:53

Ember.js: how to correctly send a crossdomain request via RESTAdapter?

There is a RESTAdapter and a controller that accesses the adapter:

export default Ember.Controller.extend({
  actions: {
    auth() {
      var a = this.store.adapterFor('auth');
      var hash = this.getProperties('login', 'password');
      a.ajax('https://192.168.18.134/rest/auth', 'GET', hash);
    }
  }
});

In the adapter, I added parameters to make crossdomain requests work:
export default RESTAdapter.extend({
  corsWithCredentials: true,
  headers: {
    'Access-Control-Allow-Origin': '*'
  }
});

On form submit, auth() is executed, a GET request is displayed in the firebug, and then a warning appears:
Запрос из постороннего источника заблокирован: Политика одного источника запрещает чтение удаленного ресурса на https://192.168.18.134/rest/auth (Причина: отсутствует токен 'access-control-allow-origin' в заголовке CORS 'Access-Control-Allow-Headers' из канала CORS preflight).

and error:
Error: Ember Data Request GET https://192.168.18.134/rest/auth returned a 0
Payload (Empty Content-Type)

and I don't know - either the parameters did not help, or some other reason.
Instead of the .ajax function, I tried using .query, but the result is the same.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Aristov, 2016-06-21
@aristov

Strange, but the headline that I spied on the Internet interfered with: I
removed it and the problems were gone.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question