Skip to content

Instantly share code, notes, and snippets.

@faisal-w
Created February 21, 2014 01:38
Show Gist options
  • Save faisal-w/9127226 to your computer and use it in GitHub Desktop.
Save faisal-w/9127226 to your computer and use it in GitHub Desktop.
How to encrypt javascript web service call with JQuery
$.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();
//...
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment