Skip to content

Instantly share code, notes, and snippets.

@pdeschen
Created May 20, 2011 19:15
Show Gist options
  • Save pdeschen/983569 to your computer and use it in GitHub Desktop.
Save pdeschen/983569 to your computer and use it in GitHub Desktop.
Ajax jQuery Authentication Request
$.ajax( {
url : '/model/user.json',
dataType : 'json',
beforeSend : function(xhr) {
var bytes = Crypto.charenc.Binary.stringToBytes(username + ":" + password);
var base64 = Crypto.util.bytesToBase64(bytes);
xhr.setRequestHeader("Authorization", "Basic " + base64);
},
error : function(xhr, ajaxOptions, thrownError) {
reset();
onError('Invalid username or password. Please try again.');
$('#loginform #user_login').focus();
},
success : function(model) {
cookies();
...
}
});
@saurabhprasadsah
Copy link

basic authentication not working..//

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment