我有一个简单的PHP脚本(create.php),它使用现有的PNG图像输出验证码图像:
<?php
session_start();
$myimg = ImageCreateFromPNG("foobar.png");
$captcha = rand(1000,9999);
$_SESSION["captcha"] = $captcha;
$font = "path/to/font";
$fontsize = 15;
$txtcolor = ImageColorAllocate($myimg, 0,0,0);
$angle = 0;
$coordx = 10;
$coordy = 20;
imagettftext($myimg,$fontsize,$angle,$coordx,$coordy,$color,$font,$captcha);
imagepng($myimg);
imagedestroy($myimg);
?>我这样调用这个脚本(output.php):
<div id="refresh">
<img src="create.php" alt="foo" />
</div>
<span id="trigger-refresh">reload</span>
<script>
$('#trigger-refresh').click(function() {
$('#refresh').load("refresh.php");
});
</script>文件refresh.php如下所示:
<?php
echo '<img src="create.php" alt="foo" />';
?>当我在浏览器中调用refresh.php时,验证码图像显示正确-一切正常。但是在output.html中触发Jquery-Function之后,图像/会话不会重新加载。它只适用于Webkit浏览器,例如Chrome。首先,我认为问题出在浏览器-chache中。所以我清理了缓存--没有任何成功。Firebug显示"refresh.php“是load,而不是"create.php”。
发布于 2015-01-21 21:20:42
也许将"refresh.php“的内容放在#refresh目录中不足以在每个浏览器中重新加载"create.php”的内容(例如,一些浏览器必须只加载"refresh.php“,而将"create.php”保留为已经加载的原样)。
我建议您在jQuery脚本中创建一个img标记,用"create.php“的内容加载它的内容,然后显示那个新的img标记。
示例代码如下:https://stackoverflow.com/a/4285068/4475293
var img = $("<img />").attr('src', 'create.php')
.load(function() {
if (!this.complete || typeof this.naturalWidth == "undefined" || this.naturalWidth == 0) {
//error
} else {
//replace your img tag with the new one
}
});https://stackoverflow.com/questions/28068079
复制相似问题