49

Вопрос по jquery – добавить заголовок запроса на магистраль

Мой сервер имеет ручную авторизацию. Мне нужно указать имя пользователя / пароль моего сервера в моем порядке запроса магистрали, чтобы он прошел. Как я могу это сделать? Есть идеи? Спасибо

9 ответов

5

Error: User Rate Limit ExceededBackbone.AuthenticatedModelError: User Rate Limit ExceededBackbone.Model.

Error: User Rate Limit Exceeded

Backbone.AuthenticatedModel = Backbone.Model.extend({
    sync: function(method, collection, options){
        options = options || {};
        options.beforeSend = function (xhr) {
            var user = "myusername";// your actual username
            var pass = "mypassword";// your actual password
            var token = user.concat(":", pass);
            xhr.setRequestHeader('Authorization', ("Basic ".concat(btoa(token))));
        };
        return Backbone.Model.prototype.sync.apply(this, arguments);
    }

});

Error: User Rate Limit ExceededBackbone.AuthenticatedModelError: User Rate Limit Exceeded

var Process = Backbone.AuthenticatedModel.extend({
    url: '/api/process',

});
42

Error: User Rate Limit Exceeded

MyCollection.fetch( { headers: {'Authorization' :'Basic USERNAME:PASSWORD'} } );
-1

  1. In the client side, add this before any server communication:

    $.ajaxSetup({
        xhrFields: {
            withCredentials: true
        },
        async: true
    });
    
  2. In the server side add these headers (PHP):

    header('Access-Control-Allow-Origin: http://your-client-app-domain');
    header("Access-Control-Allow-Methods: PUT, GET, POST, DELETE, OPTIONS");
    header("Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With");
    header('Access-Control-Allow-Credentials: true');
    
17

Error: User Rate Limit Exceeded

#coffeescript
_sync = Backbone.sync
Backbone.sync = (method, model, options) ->
    options.beforeSend = (xhr) ->
        xhr.setRequestHeader('X-Auth-Token_or_other_header' , your_hash_key)
        #make sure your server accepts X-Auth-Token_or_other_header!!
    #calling the original sync function so we only overriding what we need
    _sync.call( this, method, model, options )       
28

Error: User Rate Limit Exceeded

$.ajaxSetup({
    headers: { 'Authorization' :'Basic USERNAME:PASSWORD' }
});

Edit 2nd Jan 2018Error: User Rate Limit Exceeded

3

Object.save(
  {'used': true}
  {headers: {'Access-Token': 'access_token'}}
)
1

Error: User Rate Limit Exceeded

    REPORTING_API_KEY = 'secretKeyHere';
    CustomSync = function(method, model, options) {
        options.headers = {
            'Authorization' : 'Bearer ' + REPORTING_API_KEY
        };
        return Backbone.sync(method, model, options);
    };

Error: User Rate Limit Exceeded

    MyModel = Backbone.Model.extend({
        urlRoot: '/api/',
        sync: CustomSync
    });
10

Backbone.$.ajaxSetup({
    headers: {'Authorization' :'Basic USERNAME:PASSWORD'}
});

Error: User Rate Limit Exceededxhr.setRequestHeaderError: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

MyCollection.fetch({ headers: {'Authorization' :'Basic USERNAME:PASSWORD'} } );

Error: User Rate Limit Exceeded

MyCollection.fetch();

Error: User Rate Limit Exceeded

53

Error: User Rate Limit Exceededfetch, saveError: User Rate Limit ExceededdestroyError: User Rate Limit ExceededBackbone.syncError: User Rate Limit Exceeded

fetch, saveError: User Rate Limit ExceededdestroyError: User Rate Limit Exceeded[options]Error: User Rate Limit Exceeded[options]Error: User Rate Limit Exceeded

sendAuthentication = function (xhr) {
  var user = "myusername";// your actual username
  var pass = "mypassword";// your actual password
  var token = user.concat(":", pass);
  xhr.setRequestHeader('Authorization', ("Basic ".concat(btoa(token))));
}

Error: User Rate Limit Exceededfetch, saveError: User Rate Limit ExceededdestroyError: User Rate Limit Exceeded

 fetch({
  beforeSend: sendAuthentication 
 });

Error: User Rate Limit ExceededBackbone.syncError: User Rate Limit ExceededbeforeSendError: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Похожие вопросы