Note that there are some explanatory texts on larger screens.

plurals
  1. POUse AJAX to reload captcha
    text
    copied!<p>This question may have been asked already - but unfortunately, I could not find any satisfactory answers. I will just ask it for my concrete case and ask the admins not to delete the question for at least a few days so I can try it out...</p> <p>I have a page. It uses a captcha. Like so:</p> <pre><code>&lt;?php session_start(); // the captcha saves the md5 into the session ?&gt; &lt;img src="captcha.php" onclick="this.src = this.src" /&gt; </code></pre> <p>That was my first code. It did not work, because the browser condsidered it useless to reload an image if the source is the same. My current solution is to pass a get parameter:</p> <pre><code>onclick="this.src = 'captcha.php?randomNumber='+ranNum" </code></pre> <p>The JavaScript variable <code>var ranNum</code> is generated randomly every time the <code>onclick</code> event fires. It works fine, still, I don't like the possibility, if the - though improbable - case of two numbers being the same twice in a row. Although the random number varies between -50,000 and 50,000 - I still do not like it. And I don't think the method is right. I would like to know the 'righter' method, by means of AJAX. I know it's possible. I hope you know how it's possible ^^ In that case, please show me.</p> <p>Thanks in advance!</p> <p>By the way - if I spell cap(t)cha differently, never mind, the reference to the PHP file is right in my code: I use randomImage.php</p> <p>EDIT: The random number in JavaScript is only generated so the image reloads. Captcha.php does not care for the $_GET parameter. The string really is random.</p> <p>EDIT: Thus, what I would like to know is how to make the browser relaod the image without passing different get parameters every time the event fires.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload