我在 ColdFusion 页面上实现了验证码。我希望这些 PHP 变量的值来验证用户提交的验证码。我正在尝试通过 jQuery 中的 ajax 来做到这一点。但没有取得任何成功。这是代码: -
PHP代码:
<?php
session_start();
$word_1 = '';
for ($i = 0; $i < 4; $i++)
{
$word_1 .= chr(rand(97, 122));
}
for ($i = 0; $i < 4; $i++)
{
$word_2 .= chr(rand(97, 122));
}
$_SESSION['random_number'] = $word_1.' '.$word_2;
$dir = 'fonts/';
$image = imagecreatetruecolor(165, 50);
$font = "recaptchaFont.ttf";
$color = imagecolorallocate($image, 0, 0, 0);
$white = imagecolorallocate($image, 255, 255, 255);
imagefilledrectangle($image, 0,0, 709, 99, $white);
imagettftext ($image, 22, 0, 5, 30, $color, $dir.$font, $_SESSION['random_number']);
header("Content-type: image/png");
imagepng($image);
$var = $word_1;
//echo "http://ed-s2:81/iucn_assets/custom/rangers/reCaptcha/get_captcha.php?var=".$var;
$word_1 = $_POST['firstRanNo'];
?>
ColdFusion 文件代码(在 jQuery 中获取 PHP 变量):
function change_captcha()
{
document.getElementById('captcha').src="http://ed-s2:81/iucn_assets/custom/rangers/reCaptcha/get_captcha.php?rnd=" + Math.random();
var getNo = random_no();
var num= "abc";
function random_no(){
var res="";
$.ajax
({
type:"POST",
data:{"firstRanNo":num},
url:"http://ed-s2:81/iucn_assets/custom/rangers/reCaptcha/get_captcha.php",
async:false,
success:function(result){
alert(result);
}
});
}
}
});
可能是什么问题?