为什么这个javascript代码不起作用?
我有一个javascript函数为什么这个javascript代码不起作用?,javascript,jquery,html,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
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库。但是似乎不起作用。您得到的错误是什么 我认为这应该是:
$.ajax({
type: "POST",
url: "tokenize.php", //removed the dot
.....
“ajax不工作”是什么意思?没有发出HTTP请求吗?你怎么查的?@Quentin请求没有收到made@Quentin在console.log中,我假设得到的是一个不会出现的文本..但是ajax代码单独工作,没有这个函数如果它自己工作,并且没有发出HTTP请求,那么它必须在到达该点之前出错。JS控制台中显示了什么错误消息?我在控制台中没有收到任何错误。