生成不同的Captcha

In my website, I used simple captcha generator and I successfully generated random captcha whenever the signup page is reloaded. But when I tried to dynamically refresh the captcha (in the case it wasn't clear) without reloading all the page the captcha image still the same, and I don't understand why this happens.

the php code:

header("Content-type: image/png");
$c = new Captcha;
$c->CCaptcha();
imagepng($c->image);
imagedestroy($c->image);

And note that the Captcha is php class that generates the captcha.

my html/js code looks like:

function cap()
{
    
    document.getElementById("cimg").src = "captcha.php";
}
<img src="captcha.php?n=0" id="cimg" name = "cimg"/>
<button type="submit" onclick="cap()" ><span class = "glyphicon glyphicon-refresh"></span> Refresh </button>
    <span class = "col-sm-6"><input type="text" class="form-control" onkeyup="cap()" id="ceap" placeholder="Write the word in the image"></span>

So what is the problem, and why the image still the same unless I reload all the page?

</div>