所以我在一个预先存在的网站上工作,我试图添加一个代码发送一些数据的点。当它到达我的 .post() 时,我收到以下错误:
too much recursion
http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js
Line 16
这是流程:
一些链接文本具有以下 onclick 处理程序:
<a class="lucida_12pxBlueLH16" onclick="changeCipherAdmin(6); return false;" href="#">Keyword: SLEEP</a>
function changeCipherAdmin(num) {
tempHTML = '';
tempHTML += '<select id="select_cipher' + num + '" name="select_cipher' + num + '" class="select_tanbg" onchange="updateKeyFieldsAdmin(this.value,' + num + ',1);">';
tempHTML += ' <option id="option' + num + '_admin1" value="1">Additive</option>';
tempHTML += ' <option id="option' + num + '_admin2" value="2">Affine</option>';
tempHTML += ' <option id="option' + num + '_admin3" value="3">Caesar</option>';
tempHTML += ' <option id="option' + num + '_admin4" value="4">Keyword</option>';
tempHTML += ' <option id="option' + num + '_admin5" value="5">Multiplicative</option>';
tempHTML += ' <option id="option' + num + '_admin6" value="6">Vigenère</option>';
tempHTML += '</select>';
document.getElementById('admin_cipher' + num).innerHTML = tempHTML;
document.getElementById('option' + num + '_admin' + ciphers[num]).selected = true;
updateKeyFieldsAdmin(ciphers[num], num, 0);
}
基于此,它运行以下功能
function updateKeyFieldsAdmin(cipherNum, selectNum, resetNum) {
//tempHTML='<a href="#" onclick="changeCipherAdmin('+selectNum+'); return false;" class="lucida_12pxBlueLH16">'+possible_ciphers[cipherNum]+'</a>';
//document.getElementById('admin_cipher'+selectNum).innerHTML=tempHTML;
if (resetNum == 0) {
keyA = keysA[selectNum];
keyB = keysB[selectNum];
}
if (cipherNum == 1) {
//0-25
//change letter to number, add encryption key (two characters?), reduce mod 26
//additive: use a:number
if (resetNum == 1) {
keyA = "";
keyB = "";
}
tempHTML = '<strong class="helvetica11pxTanB">Key (0-25)</strong> <input type="text" id="key_a' + selectNum + '" maxlength="2" class="form_field11px" style="width:19px; height:12px; text-align:right; color:#000000;" value="' + keyA + '" onkeyup="checkKeysAdmin(1,' + selectNum + '); return false;" autocapitalize="off" autocorrect="off" />';
}
else if (cipherNum == 6) {
//vigenere: use a:word--26 letters or less
if (resetNum == 1) {
keyA = "";
keyB = "";
}
tempHTML = '<strong class="helvetica11pxTanB">Keyword</strong> <input type="text" id="key_a' + selectNum + '" maxlength="26" class="form_field11px" style="width:99px; height:12px; text-align:right; color:#000000;" value="' + keyA + '" onkeyup="checkKeysAdmin(event,6,' + selectNum + '); return false;" autocapitalize="off" autocorrect="off" />';
}
document.getElementById('admin_key' + selectNum).innerHTML = tempHTML;
if ((cipherNum == 2 || cipherNum == 5) && !isNaN(keyA) && keyA != "") {
//update select field
if (cipherNum == 2) {
$('#key_a' + selectNum).val(keyA);
}
else {
for (i = 1; i < odd_nums_prime26.length; i++) {
if (keyA * 1 == odd_nums_prime26[i]) {
document.getElementById('key_a' + selectNum).selectedIndex = i;
document.getElementById('option' + selectNum + '_mult' + i).selected = true;
break;
}
}
}
}
if (resetNum == 1) {
checkKeysAdmin(cipherNum, selectNum);
}
}
然后调用以下内容:
function checkKeysAdmin(e, cipherNum, row) {
encrypt_ready = true;
if (encrypt_ready == true) {
//keyA and keyB should already be updated...so:
keysA[row] = keysA;
keysB[row] = keysB;
ciphers[row] = cipherNum;
ciphertext[row] = encryptTextAdmin(plaintext[row], cipherNum);
document.getElementById('cipher' + row).innerHTML = ciphertext[row];
// This is my code where Im trying to send my data out
if (e.keyCode == 13 ) {
alert( 'here2' );
$.post('/challenges/save.php', { action:'updateJokeMessage',
messageId:message_ids[row],
joke:message_text[row],
punchline:plaintext[row],
encryptedPunchline:ciphertext[row],
cipherId:cipherNum,
keyA:keysA[row],
keyB:keysB[row]
});
alert( 'Done' );
}
return;
}
else {
//alert("not ready to encrypt");
document.getElementById('cipher' + row).innerHTML = '';
}
// me trying to stop the recursion
event.stopPropagation();
}
我尝试添加回调并放入 event.stopPropagation 或返回等。但不知道为什么。任何想法/帮助将不胜感激。