hansford Posted June 20, 2008 Share Posted June 20, 2008 Do you know why AJAX would fail to respond after the first 2 clicks? The function is called with an onclick event handler inside a button. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 20, 2008 Share Posted June 20, 2008 code please Quote Link to comment Share on other sites More sharing options...
hansford Posted June 20, 2008 Author Share Posted June 20, 2008 Heres the js file code function get_page(page) { var httpRequest; if (window.XMLHttpRequest) { httpRequest = new XMLHttpRequest(); } else if (window.ActiveXObject) { var ieXmlHttpVersions = new Array(); ieXmlHttpVersions[ieXmlHttpVersions.length] = "MSXML2.XMLHttp.7.0"; ieXmlHttpVersions[ieXmlHttpVersions.length] = "MSXML2.XMLHttp.6.0"; ieXmlHttpVersions[ieXmlHttpVersions.length] = "MSXML2.XMLHttp.5.0"; ieXmlHttpVersions[ieXmlHttpVersions.length] = "MSXML2.XMLHttp.4.0"; ieXmlHttpVersions[ieXmlHttpVersions.length] = "MSXML2.XMLHttp.3.0"; ieXmlHttpVersions[ieXmlHttpVersions.length] = "MSXML2.XMLHttp"; ieXmlHttpVersions[ieXmlHttpVersions.length] = "Microsoft.XMLHttp"; var i; for (i=0; i < ieXmlHttpVersions.length; i++) { try { httpRequest = new ActiveXObject(ieXmlHttpVersions[i]); } catch (e) { alert(ieXmlHttpVersions[i] + " not supported."); } } } if(document.getElementById('article_no')){ article = document.getElementById('article_no').value; } else{ article = page; } if(typeof(httpRequest) != 'undefined') { var url = 'requestarticle.php?page='; httpRequest.open('GET',url + article, true); httpRequest.send(null); httpRequest.onreadystatechange= function() { if(httpRequest.readyState==4) { var content = httpRequest.responseText; document.getElementById("admin").innerHTML = content; } } } } heres the html file <html> <script language='javascript' src='ajax_request_db.js'></script> <body> <div id='admin'> <table width="400" border="1" align="center"> <tr> <td align="center" colspan="2"><h1>Articles<br/><br/></td> </tr> <tr> <td align="center" colspan="2"><div id='auth'></div></td> </tr> <tr><form action="" method="post" name="adminlogin"> <td align="right">Article number:</td><td><input type='text' id='article_no' size="10" maxlength="6"></td> </tr><tr> <td colspan="2"><input type="button" name='fetch' id='fetch' value="Get Article" onclick="get_page('fetch');"/></td> </tr></form> </table> <p> </p> </div> </body> </html> Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 20, 2008 Share Posted June 20, 2008 My guess would be it revolves around variables scope. Save yourself the trouble and just use a JS library like jQuery Quote Link to comment Share on other sites More sharing options...
miracle_potential Posted June 21, 2008 Share Posted June 21, 2008 I'm having a similar problem where sometimes my Ajax preloader doesnt load and you have to close the window and start it all up again maybe its an IE problem? Quote Link to comment Share on other sites More sharing options...
hansford Posted June 22, 2008 Author Share Posted June 22, 2008 I solved the immediate problem. IE does have some issues, but I can't quite pin the documentation of the problem/problems down. I tweaked my code following this example and it worked as far as this issue is concerned. http://www.phpfreaks.com/forums/index.php/topic,115581.0.html The key from the example is all the if/else conditions right down to a complete failure. My original code was similar to this, but I didn't have all the conditions as -why would they be needed-but it seems they are-for IE anyways. If you can't get your code running from this example, then reply and I will post my code as an example. NOTE: the entire code including checking for the ajax object needs to be contained in one function otherwise you will have problems in IE. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.