It could be browser caching. In other words the browser sees that it already loaded captcha.php
so it does not need to load it again.
Try appending a query string to the image source that includes the current time. Since the image source will now be a URL that the browser has not loaded before it will try to reload it.
<img id="captcha" src="captcha.php">
<a id='reload'>Refresh now</a>
$('#reload').click(function(){
$('#captcha').attr('src','captcha.php?' + (new Date()).getTime());
});
Better yet, set the HTTP headers on captcha.php
to ensure the browser will not cache it.
<?php
// Set headers to NOT cache a page
header("Cache-Control: no-cache, must-revalidate"); //HTTP 1.1
header("Pragma: no-cache"); //HTTP 1.0
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
?>
Source: https://stackoverflow.com/a/4485194/284685