Guest User

Untitled

a guest
Jan 14th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. JQuery for basic authentication random behavior?
  2. function make_basic_auth(un, pss)
  3. {
  4. var tok = un + ':' + pss;
  5. var hash = Base64.encode(tok);
  6. return "Basic " + hash;
  7. }
  8.  
  9. $('#loginform').submit(function()
  10. {
  11. var username = $('.username').val();
  12. var password = $('.passcode').val();
  13.  
  14. $.ajax({
  15. type: 'POST',
  16. url: 'serverIP/loginService',
  17. contentType: "application/json",
  18. **async: false**,
  19. beforeSend: function(xhr)
  20. {
  21. var auth = make_basic_auth(username, password);
  22. xhr.setRequestHeader('Authorization', auth);
  23. },
  24. success: function (xhr, status){
  25. alert(status);
  26. },
  27. error: function (xhr, status){
  28. alert(status);
  29. }
  30. });
  31. });
Add Comment
Please, Sign In to add comment