为什么这个javascript代码不起作用?

时间:2014-03-30 09:10:15

标签: javascript jquery html

我有一个javascript函数

function TxEncrypt(event)
{ //perform encryption of token data, then submit the form like normal

    //obtain public key and initial JSEncrypt object
    var txPubKey = txJ$(".zwitch_encryptionkey").val();
    var txEncrypter = new JSEncrypt();
    txEncrypter.setPublicKey(txPubKey);

    //get Data and encrypt it
    var txData = '{}';
    var txCryptData = '';
    if(txJ$(".zwitch_data").length > 1)
    { //if there are more than one element with this class, convert it to json string
        txData = txJ$(".zwitch_data").serializeObject();
        txCryptData = txEncrypter.encrypt(JSON.stringify(txData));
    }
    else
    {   //else, just encrypt the value
        txData = txJ$(".zwitch_data").val();
        txCryptData = txEncrypter.encrypt(txData);
    }


    dataString = txCryptData; // array?
    $.ajax({
            type: "POST",
            url: "tokenize.php",
            data: {data : dataString}, 
            cache: false,
            success: function(data) {
                returnedvalue = data;
                console.log(data); //alert isn't for debugging
            }
    });

    alert(dataString);
}

我可以得到dataString的值。但是ajax parrt不起作用。我已经添加了jquery库。但似乎没有工作

1 个答案:

答案 0 :(得分:0)

你得到的错误是什么?

我认为这应该是:

$.ajax({
    type: "POST",
    url: "tokenize.php", //removed the dot
    .....