0

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?

The Alpha
  • 143,660
  • 29
  • 287
  • 307
Fakhr Alam
  • 203
  • 1
  • 5
  • 12

5 Answers5

3

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?

Cal
  • 7,067
  • 25
  • 28
  • $(function(){ $("#btn").click(function(){ $("img").attr('src','image.php'); alert(9);//works in all browsers }); }); – Fakhr Alam Apr 06 '12 at 04:42
2

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());
});
sakhunzai
  • 13,900
  • 23
  • 98
  • 159
1

Maybe try this approach of adding a query string to prevent the browser caching.

How to reload/refresh an element(image) in jQuery

Community
  • 1
  • 1
Paul
  • 1,122
  • 1
  • 10
  • 18
1

Try this code

$(function(){

  $("#btn").live("click",function(){ 

       $("img").attr('src','image.php');  

  });
});
gen_Eric
  • 223,194
  • 41
  • 299
  • 337
Mahipal
  • 126
  • 5
0

$("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

Fakhr Alam
  • 203
  • 1
  • 5
  • 12