Skip to content

Instantly share code, notes, and snippets.

@louismullie
Last active March 25, 2019 16:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save louismullie/6159542 to your computer and use it in GitHub Desktop.
Save louismullie/6159542 to your computer and use it in GitHub Desktop.
Encrypted AJAX wrapper for jQuery.
var key = 'password';
$.encAjax = function (url, options) {
options.data = options.data || {};
var data = JSON.stringify(options.data);
var encryptedData = sjcl.encrypt(key, data);
options.data = { data: encryptedData };
var success = options.success;
options.success = function (jsonResponse) {
var txtResponse = JSON.stringify(jsonResponse);
var decryptedResponse = sjcl.decrypt(key, txtResponse);
success(JSON.parse(decryptedResponse));
};
$.ajax(url, options);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment