5

I found this code which makes it possible to authenticate using setRequestheader and Ajax.

this.xmlDoc.setRequestHeader('Authorization','Basic ' + Base64.encode("User:Password"));

Unfortunatily I have no knowledge of Ajax and Base64 does not seem to be class or method I can reference. Is there an alternative for this Basic encryption? Or a simular encode function I can call from Javascript?

Thank you !

Anonymoose
  • 2,389
  • 6
  • 36
  • 69
  • What kind of request are you trying to authorize? The code sample you gave adds authorization to an xmlhttprequest, is that what you're doing? – just.another.programmer Jul 20 '12 at 11:02
  • Yes, sorry for not specifying. this.xmlDoc=!_isIE&&window.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP"); – Anonymoose Jul 20 '12 at 11:05
  • 1
    @user1365889 You could google [javascript base64 encode](http://www.google.com/?q=javascript+base64+encode) which is what all the answers you get will have done – Esailija Jul 20 '12 at 11:13

1 Answers1

2

You need a function to Base64 encode the User:Password string. See this question which gives a couple of good options to do this in javascript.

Community
  • 1
  • 1
just.another.programmer
  • 8,579
  • 8
  • 51
  • 90