Skip to content

How do I set headers with ajax() method? #35

@millisami

Description

@millisami

I want to attach request headers with ajax() method.
I tried with the following syntax, but its not working:

   var headers = {'Authorization': this.session.content.token}   
   return ajax({
            type: 'GET',
            url: "http://localhost:3000/places/" + location.latitude + "/" + location.longitude + "/2000.json",
            beforeSend: function (request) {
              request.setRequestHeader(headers);
            }
        });

But get the error in setRequestHeader:

 Error while processing route: index undefined is not a function TypeError: undefined is not a function
    at Object.jQuery.extend.ajax.jqXHR.setRequestHeader (http://localhost:4200/assets/vendor.js:9106:23)
    at Object.__exports__.default.Ember.Route.extend.model.get.getLocation.then.ajax.beforeSend (cabbyguide/routes/index.js:24:27)
    at Function.jQuery.extend.ajax (http://localhost:4200/assets/vendor.js:9259:39)
    at http://localhost:4200/assets/vendor.js:61982:17
    at initializePromise (http://localhost:4200/assets/vendor.js:59039:9)
    at new Promise (http://localhost:4200/assets/vendor.js:60635:9)
    at makePromise (http://localhost:4200/assets/vendor.js:61971:14)
    at raw (http://localhost:4200/assets/vendor.js:61930:14)
    at request (http://localhost:4200/assets/vendor.js:61917:18)
    at eval (cabbyguide/routes/index.js:20:18)

How do I set the headers?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions