Jump to content

Only Works Once In Firefox?


Zaper Gallis

Recommended Posts

This is a strange one to me. I wrote a captcha script for my site which works fine. On the sign up page I put it on I have a JavaScript function that uses ajax to refresh the captcha without reloading the page. That works in all my browsers but Firefox and Opera. In these browsers you can click it once and it works, after that it doesn't refresh the image. When add an alert at the end of the function it shows that the function is firing, so it's acting like the page is caching, even though I'm sending it with POST. Does any one know why these two browsers are doing that and how to stop it? The code is:

function loadXMLDoc(div){if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safarixmlhttp=new XMLHttpRequest();}else{// code for IE6, IE5xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}xmlhttp.onreadystatechange=function(){if (xmlhttp.readyState==4 && xmlhttp.status==200){	  document.getElementById(div).innerHTML=xmlhttp.responseText;}}}function refreshcaptcha (){loadXMLDoc("captcha")    xmlhttp.open("POST","refreshcaptcha.php",true);xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');xmlhttp.send();}

Link to comment
Share on other sites

I've already tried that one, thanks though. It was my understanding that POST doesn't catch in AJAX, though I may have miss understood that. It acts like it's catching, but only in 2 out of 5 browsers. Any other ideas? Notes: I've entered in all the no catch headers i could find on the PHP page that the request is sent to, and tried all the common stuff you can find on Google.

Link to comment
Share on other sites

It's not whether the method is get or post, it's really whether you add a query string to the URL.Did you see this part of the code I presented?"refreshcaptcha.php?r=" + Math.random()

Link to comment
Share on other sites

The other possibility is that your PHP script is always returning the same data. If you have Firebug you can see if the response is loaded from cache or not.

Link to comment
Share on other sites

Now I'm even more confused. First off i realized the Ajax was unnecessary, So I switched to DHTML to do the same job. Now when i try to use the script 1 of 2 things happen: If I don't load fire bug with the script it does the same thing as before, doesn't refresh the image. If I do load fire bug then it ether does the same thing as before, or, most often, it works, but the resulting image from fire bug is different than on the webpage, and the firebug code works but not the site code. I don't have the first clue wtf is going on now. It's like firebug sends it's own request to the captcha page and resets it for the main page, but if fire bug doesn't do that then the main page catches the data.

Link to comment
Share on other sites

	  document.getElementById(div).innerHTML=xmlhttp.responseText;

If xmlhttp.responseText is a string containing an <img src=''> element, have you tried putting the random URL query on that URL? eg.
echo '<img src="filename.png?r='.rand().'" />';

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...