How to include header in ajax request?

前端 未结 3 1600
情话喂你
情话喂你 2021-01-24 18:37

I need to include a header with a refresh token in an ajax call to the YouTube api. I am trying to send a delete request, to delete a movie I have on my account. This is my ajax

3条回答
  •  忘掉有多难
    2021-01-24 19:05

    I was able to pass along a header using this code below:

        jQuery.ajax({
            type: 'DELETE',
            // must set api key
            url: 'https://www.googleapis.com/youtube/v3/videos?id='+ thisUniqueID +'&key=api_key_here',
    beforeSend: function(xhr){xhr.setRequestHeader('Authorization', 'Bearer access_token_here');},
            success: function() {
            alert('your video has been deleted');
            },
            error: function() {
            alert('error processing your request');
            }
        }); 
    

提交回复
热议问题