shv22 shv22 - 5 months ago 17
Ajax Question

Ajax call on success not working

I have to convert a encrypted data response back to plain text.

For this I am using a ajax post call to get the data response and than on sucess passing that data response a decrypto function and getting back the response in plain text (this is the idea)

Now, when I created a Ajax post call and than passing that decrypto their on success nothing is happening

I am sure my decrypto is working

Here is working fiddle for that

https://jsfiddle.net/yktup39e/

Now, problem is in the Ajax. I have only once make an Ajax call so I pretty much sure there will problem in that. But I am not getting that.

This is my code-

JS -

$('#action-button').click(function() {
var settings = {
async: true,
crossDomain: true,
url: "http://192.168.168.76:8080/HTMLPortingNewService/GetData?ChartName=widget3LineChart&lob=M&carrier=0&enrollmenttype=0&state=0&agent=0&fromdate=04%2F03%2F2015&todate=05%2F03%2F2015&requestID=499F6BF5E4610454A887AB37AF0814E8",
method: "POST",
headers: {
"cache-control": "no-cache",
"postman-token": "ac20a050-a8c8-6d58-4350-66141d519394",
"content-type": "application/x-www-form-urlencoded"
},
data: {
"username": "aHRtbHVzZXIx",
"password": "SHRtbDIwMTY="
}
}

$.ajax(settings).done(function (response) {
console.log(response);
decrypted = decryptByDES(response,DES);
console.log(decrypted);
});
});

function decryptByDES(cipherTextString, keyString) {
var keyHex = CryptoJS.enc.Utf8.parse(keyString);

var decrypted = CryptoJS.DES.decrypt({
ciphertext: CryptoJS.enc.Base64.parse(cipherTextString)
}, keyHex, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});

alert(decrypted);

return decrypted.toString(CryptoJS.enc.Utf8);
}


HTML -

<script src="tripledes.js"></script>
<script src="mode-ecb.js"></script>


<button id="action-button">Click me to load info!</button>
<div id="info"></div>


Can anyone please help me with that??

Answer

Try to include jquery in your page.

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.0/jquery.js"></script> 
Comments