简体   繁体   English

Ajax请求失败

[英]Ajax request is getting failed

var x;

function addtoDom() {
    console.log("Adding to DOm");
    $("#capt").html('<div id="mduit"><img src="captcha1.jpg"></div>');
}

function request() {
    $.ajax({
        url: "mudit.php",
        type: "GET",
        success: function (data) {
            console.log(data);
            x = data;
            addtoDom();
        }
    });
}

request();

Mudit.php goes here Mudit.php转到这里

<?
// header("Content-type:image/jpeg");

session_start();
$img = imagecreate(150,60);
imagecolorallocate($img,200,255,200);
$abc = rand();

while ($abc < 10000) {
    $abc = rand();  
}

$_SESSION['Captcha_num'] = $abc;
imagettftext($img,35,0,0,40, 89,"abcd.ttf", $abc);
imagejpeg($img,"captcha1.jpg",65);
echo $abc;
?>

here the code is working fine in chrome but not working in firefox. 这里的代码在chrome中工作正常,但在Firefox中不工作。 ie while refresing the image on click refresh button .. captcha refreshes in chrome but not in firefox. 即在点击刷新按钮时刷新图像..验证码会在chrome中刷新,但不会在Firefox中刷新。

This is probably caching issue. 这可能是缓存问题。 Try this: 尝试这个:

function addtoDom() {
    $("#capt").html('<div id="mduit"><img src="captcha1.jpg?' + +new Date() +  '"></div>');
}

Here captcha1.jpg will be forced to refresh due to new GET parameter on every click. 由于每次单击都使用新的GET参数,因此将强制刷新captcha1.jpg。

Also don't do this: 也不要这样做:

echo $abc;

it doesn't make sense, since it's secret and you don't want to provide client with this value. 这是没有意义的,因为它是秘密的,并且您不想为客户提供此值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM