I have created PHP GD image for captcha, file called image.php
each time it generates a dynamic captcha image.
In signup.php
I have
<img alt="" src="image.php">
<input type="button" id="btn" value="cant read captcha">
<!--btn is to load another captcha-->
jscript.js
$("#btn").click(function(){
$("img").attr('src','image.php');
});
Works in Chrome, Safari, and Opera but not in IE and Firefox.
How can I fix this or are there any alternative solutions?
$("image").attr("src","image.php?timestamp=" + new Date().getTime());
I think it was an issue of caching
firefox and ie does not pick image from source again and again
but it loads from its cache
by changing name of image it is now working for me in all browsers
thanx every one
Is the code running after the dom loads? If not, try:
$(function(){
$("#btn").click(function(){
$("img").attr('src','image.php');
});
});
Is there an error in your console?
Try a adding random number at the end of the url , this might be cache issue e.g
$("#btn").click(function(){
$(this).prev("img").attr('src','image.php?rnd='+Math.random());
});
Maybe try this approach of adding a query string to prevent the browser caching.
Try this code
$(function(){
$("#btn").live("click",function(){
$("img").attr('src','image.php');
});
});