Set Headers in Ajax Request

  ## I used Coffee Script syntax
  ## @ sign here to set this function available in .erb file

  @yourFunction = (auth_token) ->
    $.ajax({
      type: "GET",
      url: "/url/path",
      headers: { 'Authorization': 'Token token=' + auth_token }
    }).done((data) -> console.log(data)
    ).fail((jqXHR, textStatus, errorThrown) -> 
      console.log("Request failed: " + textStatus)
      console.log(errorThrown)
    });

Published by

Colin Dao

I am a hardworking Rubyist in Hanoi, Vietnam

Leave a comment