Put header in ajax get method

3

Good afternoon, I have the following piece of code:

function getData(){

    var url = "http://teste.com";
    var data = "";

    $.get(url, function(response){

    serverResponse = response;

        for(i in response.content){


            data +='\
            <tr>\
                <td>'+response.content[i].TesteId+'</td>\
                <td>'+response.content[i].TesteNome+'</td>\
                <td>'+response.content[i].TesteEmail+'</td>\
           </tr>';
        }

        $('#corpotabela').empty();
        $('#corpotabela').append(data);

        var width = new Array();
        $(".table-body tr:eq(0)").find('td').each(function (position){
            width[position] = $(this).outerWidth();
        });
        $(".table-header tr").find('th').each(function (position){
            $(this).css("width", width[position]+2);
        });

    });
}

However, to get this request I need to send a token in the header. Can I do this using this jQuery method?

    
asked by anonymous 15.12.2015 / 17:18

1 answer

1

You will need to do something like this

$.ajax({
   url : myurl,
   headers: {
        'X-Auth-Token' : token
   });

For more information on how to do this, read the doc $ .ajax ();

    
15.12.2015 / 17:23