Connecting Tech Pros Worldwide Help | Site Map

Problem updating an image through js

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 18th, 2006, 11:55 PM
julianmlp@gmail.com
Guest
 
Posts: n/a
Default Problem updating an image through js

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>


  #2  
Old July 19th, 2006, 12:35 AM
Rik
Guest
 
Posts: n/a
Default Re: Problem updating an image through js

julianmlp@gmail.com wrote:
Quote:
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';
Quote:
>
>
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


  #3  
Old July 19th, 2006, 12:35 AM
julianmlp@gmail.com
Guest
 
Posts: n/a
Default Re: Problem updating an image through js


Rik wrote:
Quote:
julianmlp@gmail.com wrote:
Quote:
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';
Quote:


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

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.