Ajax呼吁成功不起作用

时间:2016-06-14 07:49:49

标签: javascript jquery html ajax encryption

我必须将加密数据响应转换回纯文本。

为此,我使用ajax post调用来获取数据响应,而不是通过成功传递数据响应解密函数并以纯文本形式返回响应(这是想法)

现在,当我创建一个Ajax帖子调用而不是将其解密时,他们的成功没有发生任何事情

我确信我的解密工作

这是工作的小提琴

https://jsfiddle.net/yktup39e/

现在,问题在于Ajax。我只做过一次Ajax调用,所以我非常肯定会有问题。但我没有得到它。

这是我的代码 -

JS -

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:fresco="http://schemas.android.com/apk/res-auto"
    android:id="@+id/fl_item"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_gravity="center">
    <ImageView
        android:id="@+id/iv_icon"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:scaleType="centerCrop"
    />
</FrameLayout>

HTML -

$('#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);
}

任何人都可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

尝试在页面中包含jquery。

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.0/jquery.js"></script> 
相关问题