By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,627 Members | 1,916 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,627 IT Pros & Developers. It's quick & easy.

Problem updating an image through js

P: n/a
Note that captcha.php, generates a png image. I know it works well,
beacause in page load, I've
<img id="mainimage" src"simplecaptcha/captcha.php">
and the image is generated as expected,

but as soon as I want to reload the image, I can't
Note that I tried both with absolute and relative paths to the php
file, and neither work
<a href="javascript:void(0)" onclick="ReloadCaptcha();">give me an
easier one!</a>
<script type="text/javascript">

function ReloadCaptcha(){
alert ('ReloadCaptcha');

///document.getElementById('mainimage').src='http://MYSITE/simplecaptcha/captcha.php';
document.getElementById('mainimage').src='simpleca ptcha/captcha.php';
return true;
}
</script>

Jul 18 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Rik
ju*******@gmail.com wrote:
Note that captcha.php, generates a png image. I know it works well,
beacause in page load, I've
<img id="mainimage" src"simplecaptcha/captcha.php">
and the image is generated as expected,

but as soon as I want to reload the image, I can't
Note that I tried both with absolute and relative paths to the php
file, and neither work
<a href="javascript:void(0)" onclick="ReloadCaptcha();">give me an
easier one!</a>
<script type="text/javascript">

function ReloadCaptcha(){
alert ('ReloadCaptcha');

///document.getElementById('mainimage').src='http://MYSITE/simplecaptcha/cap
tcha.php';
>

document.getElementById('mainimage').src='simpleca ptcha/captcha.php';
return true;
}
in captcha.php:

<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
?>

Which isn't always obeyed be browsers.

You could create a random number, and set the source to
captcha.php?cachebypass=random_number
--
Rik Wasmus
Jul 19 '06 #2

P: n/a

Rik wrote:
ju*******@gmail.com wrote:
Note that captcha.php, generates a png image. I know it works well,
beacause in page load, I've
<img id="mainimage" src"simplecaptcha/captcha.php">
and the image is generated as expected,

but as soon as I want to reload the image, I can't
Note that I tried both with absolute and relative paths to the php
file, and neither work
<a href="javascript:void(0)" onclick="ReloadCaptcha();">give me an
easier one!</a>
<script type="text/javascript">

function ReloadCaptcha(){
alert ('ReloadCaptcha');
///document.getElementById('mainimage').src='http://MYSITE/simplecaptcha/cap
tcha.php';


document.getElementById('mainimage').src='simpleca ptcha/captcha.php';
return true;
}

in captcha.php:

<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
?>

Which isn't always obeyed be browsers.

You could create a random number, and set the source to
captcha.php?cachebypass=random_number
I solved it doing this way
document.getElementById('mainimage').src='http://REALPATH/captcha.php?'
+ Math.random();

Doing that, I create everytime a "new" url. That seems to be the reason
why it works.

Anyway, thanks for your answer

regards - julian

Jul 19 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.