lundi 11 juillet 2016

JavaScript - failing to submit username, password

Failing to submit the username/password using JavaScript but with general web-browser's, while using direct url in address bar it works by inserting the username password manually in the popup.

How to fix it?

<script>
function make_base_auth(user,password) {
  var tok = user + ':' + password;
  var hash = btoa(tok);
  return "Basic " + hash;
} // ends

$(document).ready(function() {  
  $.ajax({
    type: "GET",
    url: "http://www.example.be/a/b/c?id=9990",
    dataType: 'xml',
    async: false,
    data: '',
    beforeSend: function(xhr)
    {
      xhr.setRequestHeader('Authorization', make_base_auth("user1", "1234"));
    },
    success: function (data, textStatus, jqXHR){
      console.log(data, textStatus, jqXHR);
    }
  });  
});
</script>

ERROR from server:

enter image description here

Aucun commentaire:

Enregistrer un commentaire