【发布时间】:2016-09-12 17:22:37
【问题描述】:
在我的页面中,我有一个 img 显示 captcha 代码和一个 img 在单击时刷新 captcha 代码,而不是整个页面。在chrome 中,它运行良好,每次单击时都会刷新代码,但在IE 中,单击img 时没有任何反应,并且要刷新captcha 代码,您必须重新加载页面。IE这个问题怎么解决?
<img name="capImg" id="capImg" src="php/captcha.php">
<img src="images/recaptcha.png" onClick="resetCap();">
脚本:
function resetCap(){
var ajaxRequest;
try{
ajaxRequest = new XMLHttpRequest();
} catch (e){
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
return false;
}
}
}
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4 && ajaxRequest.status == 200){
document.getElementById('capImg').src = "php/captcha.php";
}
}
ajaxRequest.open("GET", "php/captcha.php", true);
ajaxRequest.send();
}
验证码.php:
<?php
session_start();
$backImage = imagecreatefrompng('C:\xampp\htdocs\service\images\captchaBack.png');
$shadowColor = imagecolorallocate($backImage, 150, 150, 150);
$textColor = imagecolorallocate($backImage, 50, 50, 50);
$font_path = 'C:\xampp\htdocs\service\fonts\times_new_yorker.ttf';
$text = NULL;
for($i=0; $i<6; $i++) $text .= mt_rand(0,9);
$_SESSION['capCode'] = $text;
imagettftext($backImage, 28, 2, 13, 38, $shadowColor, $font_path, $text);
imagettftext($backImage, 28, 2, 15, 40, $textColor, $font_path, $text);
header('Content-type: image/png');
imagepng($backImage);
imagedestroy($backImage);
?>
【问题讨论】: