Zaper Gallis Posted October 1, 2011 Share Posted October 1, 2011 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 More sharing options...
Ingolme Posted October 1, 2011 Share Posted October 1, 2011 If the problem is caching, this should stop it: xmlhttp.open("POST","refreshcaptcha.php?r=" + Math.random(),true); Link to comment Share on other sites More sharing options...
Zaper Gallis Posted October 2, 2011 Author Share Posted October 2, 2011 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 More sharing options...
Ingolme Posted October 2, 2011 Share Posted October 2, 2011 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 More sharing options...
Zaper Gallis Posted October 2, 2011 Author Share Posted October 2, 2011 Yes, I've tried adding random variables to the URL but it still didn't solve the issue. I don't even think catching is the problem. Are there any other types of issues that would look and act like caching? Link to comment Share on other sites More sharing options...
Ingolme Posted October 2, 2011 Share Posted October 2, 2011 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 More sharing options...
Zaper Gallis Posted October 2, 2011 Author Share Posted October 2, 2011 Ok, just installed Firebug. I hear a lot about it but have never used it before. Let me try to figure it out then maybe i can give more information about the issue. Thanks. Link to comment Share on other sites More sharing options...
Zaper Gallis Posted October 2, 2011 Author Share Posted October 2, 2011 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 More sharing options...
JamesB Posted October 2, 2011 Share Posted October 2, 2011 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 More sharing options...
Zaper Gallis Posted October 2, 2011 Author Share Posted October 2, 2011 Didn't know you could do that in an image link, or even think about the request page for that matter. That did the trick, thanks for the help guys. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.