rest api azure devops

rest api azure devops

Hi, I'm really struggling to get the authenication header to work, to access my azure devops. I've tested the path and the Personal Access Token (PAT) with powershell. Everything works. 
I just cannot get the same to work in javascript/jquery. Please see my code below. I've put down two different ways I've tried and commented it them out. would really appreciate the help.

// var username = "username";
// var password = "54--PAT-TOKEN--xq";

var vstsAuthHeader = { "Authorization": "Basic " + btoa("" + ":" + "54--PAT-TOKEN----xq") }


   $.ajax({
    url: 'https://dev.azure.com/organisation/projectname/_apis/wit/workitems/45?api-version=5.0',
    type: "GET",
    dataType: 'JSON',
 beforeSend: function (xhr){ 

                //xhr.setRequestHeader('Authorization', "Basic "+ btoa(username + ':' + password)); 
 
       xhr.setRequestHeader(vstsAuthHeader);
    
},
    success: function(data){
        if (data.success) {
          

     alert("Oh yes!");

 }
        else{
            alert("Oops, an error occurred fetching the remote data.");
        }
    }
   });

Thanks
Russ