您好,
这是我之前发布的完整代码。问题是整个PHP代码工作正常但javascript代码无法正常工作。我甚至无法在我用于测试目的的javascript代码中打印第一行。任何人都可以告诉我它的原因。谢谢,
[code]
<!doctype HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>AES (Rijndael) Encryption Test in JavaScript</title>
<script src="aes-enc.js" type="text/javascript" language="JavaScript"></script>
<script src="aes-dec.js" type="text/javascript" language="JavaScript"></script>
<script src="aes-test.js" type="text/javascript" language="JavaScript"></script>
<script type="text/javascript">
function doDecryption()
{
document.write("Inside Javascript");
var ct, key;
var theForm = document.forms[0];
blockSizeInBits=128;
keySizeInBits = theForm.keySize[theForm.keySize.selectedIndex].value;
if (theForm.key.value.toLowerCase().indexOf("0x") == 0)
theForm.key.value = theForm.key.value.substring(2);
if (theForm.ciphertext.value.toLowerCase().indexOf("0x") == 0)
theForm.ciphertext.value = theForm.ciphertext.value.substring(2);
if (theForm.key.value.length*4 != keySizeInBits)
{
alert("For a " + keySizeInBits + " bit key, the hex string needs to be " +
(keySizeInBits / 4) + " hex characters long.");
if (theForm.key.select)
theForm.key.select();
return;
}
if (theForm.ciphertext.value.length*4 != blockSizeInBits)
{
alert("For a " + blockSizeInBits + " bit block, the hex ciphertext string needs to be " +
(blockSizeInBits / 4) + " hex characters long.");
if (theForm.ciphertext.select)
theForm.ciphertext.select();
return;
}
ct = hex2s(<?php echo $myValue; ?>);
document.write("Inside Javascript");
document.write(ct);
// key = hex2s(theForm.key.value);
// theForm.plaintext.value = byteArrayToHex(rijndaelDecrypt(ct, key, "ECB"));
}
</script>
</head>
<body>
<?php
mysql_connect("localhost","root","");
mysql_select_db("encryption") or die(mysql_error());
$userId = $_POST['userId'];
if (($_SERVER['REQUEST_METHOD'] == 'POST') && ($_POST['key'] == ""))
{
$query = mysql_query("select * from employee_details where id = '$userId'");
if($row=mysql_fetch_assoc($query))
{
echo '<tr>';
foreach($row as $value)
echo '<td>'.$value.'</td>';
echo '</tr>';
}
else { echo "No rows returned"; }}
else if (($_SERVER['REQUEST_METHOD'] == 'POST') && ($_POST['key']))
{
$columname = "ciphertext";
$tablename = "employee_details";
function getField($field, $tbl_name, $condition)
{
$result = mysql_query("SELECT $field FROM $tbl_name WHERE id = ".$condition);
return @mysql_result($result, 0);
}
$myValue = getField($columname,$tablename,$userId);
echo "$myValue";
echo '<script type="text/javascript">
doDecryption();
</script>';
echo "whats happening";
//doDecryption();
}
?>
</body>
</html>
[/code]