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 !
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 !
Share Improve this question asked Jul 20, 2012 at 11:00 AnonymooseAnonymoose 2,4917 gold badges40 silver badges71 bronze badges 3- 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 Commented Jul 20, 2012 at 11:02
- Yes, sorry for not specifying. this.xmlDoc=!_isIE&&window.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP"); – Anonymoose Commented Jul 20, 2012 at 11:05
- 1 @user1365889 You could google javascript base64 encode which is what all the answers you get will have done – Esailija Commented Jul 20, 2012 at 11:13
1 Answer
Reset to default 2You 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.