0

Based on answers of the this and this questions, i wrote the following code to GET:

var setHeader = function (xhr) {
    xhr.setRequestHeader("Authorization", "Basic " + btoa($rootScope.login.Gebruikersnaam + ":" + $rootScope.login.Wachtwoord));
}

$rootScope.getCollection = function () {
    return new(Backbone.Collection.extend({
            url : $rootScope.login.Serverlocatie + '/Table?Active=true&SL=ID'
        }));
}

$rootScope.getCollection().fetch({
    beforeSend : setHeader
}).then(function (a) {
    console.log(a);
});

Normally, it should do a GET operation with the specified request header. However, i take the following as response:

Request Method:OPTIONS
Status Code:400 Not a REST method:

So, OPTIONS method is not allowed and if i do just a GET operation (using ajax), it is working well.

The question is: how can i make GET call instead of OPTIONS in this case?

Community
  • 1
  • 1
Asqan
  • 4,319
  • 11
  • 61
  • 100

1 Answers1

0

You can pass type field into fetch attributes:

$rootScope.getCollection().fetch({
    beforeSend : setHeader,
    type: 'GET'
}).then(function (a) {
    console.log(a);
});
t1m0n
  • 3,413
  • 1
  • 17
  • 21