Created
February 21, 2014 01:38
-
-
Save faisal-w/9127226 to your computer and use it in GitHub Desktop.
How to encrypt javascript web service call with JQuery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.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
http://blog.rassemblr.com/2011/05/jquery-ajax-and-rest-http-basic-authentication-done-deal/