I had a need to do basic authentication with JQuery (Not the most secure, I know, but some sites only accept this method).
I found the following page:
HTTP Basic Authentication using AJAX | Waves
It involves encoding the username and password with a Base64 library, and then setting the request header for the ajax call, like this:
$.ajax({
'url': 'http://host.com/action/',
'otherSettings': 'othervalues',
'beforeSend': function(xhr) {
xhr.setRequestHeader("Authentication", "Basic " + encodeBase64(username + ":" + password) //May need to use "Authorization" instead
},
sucess: function(result) {
alert('done');
}
});
EDIT 11/2/2010:
Some people have been noting that "Authorization" instead of "Authentication" seems to work better for them. The "Authentication" method works for me - I found it from this question on stack overflow: http://stackoverflow.com/questions/671042/using-javascript-with-the-twitter-api/671054#671054
I found the following page:
HTTP Basic Authentication using AJAX | Waves
It involves encoding the username and password with a Base64 library, and then setting the request header for the ajax call, like this:
$.ajax({
'url': 'http://host.com/action/',
'otherSettings': 'othervalues',
'beforeSend': function(xhr) {
xhr.setRequestHeader("Authentication", "Basic " + encodeBase64(username + ":" + password) //May need to use "Authorization" instead
},
sucess: function(result) {
alert('done');
}
});
EDIT 11/2/2010:
Some people have been noting that "Authorization" instead of "Authentication" seems to work better for them. The "Authentication" method works for me - I found it from this question on stack overflow: http://stackoverflow.com/questions/671042/using-javascript-with-the-twitter-api/671054#671054