mardi 21 avril 2015

how send ember js header request without ember data

I try to make a call to the wp-api.org plugin for Wordpress. I want to show all users en need authentication and want to use cookie authentication. Therefor I need to send a header request explained on the website like this:

options.beforeSend = function(xhr) {
    xhr.setRequestHeader('X-WP-Nonce', WP_API_Settings.nonce);

    if (beforeSend) {
        return beforeSend.apply(this, arguments);
    }
};

The following code I am using in my model:

App.UsersRoute = Ember.Route.extend({
  model: function() {
     return Ember.$.ajax({
          url: "http://ift.tt/1OaqCtJ",
          type: "GET",
          dataType: "json",
          data: JSON.stringify({}),
          beforeSend:  xhr.setRequestHeader('X-WP-Nonce', WP_API_Settings.nonce);
        });


  }
});

At the moment the sites returns this message because the authentication is fail. but I am logged in en cookies are set.[{"code":"json_user_cannot_list","message":"Sorry, you are not allowed to list users."}]




Aucun commentaire:

Enregistrer un commentaire