53329 Posted October 26, 2007 Share Posted October 26, 2007 I think there is a problem with my ajaxRequest.readyState because initially it worked but now when you load the page it doesn't. ajaxRequest.readyState should return as 1 when the page is initially loading but for some reason it just displays the blank page until it finishes. Not sure what I changed but I know that I did have it working. It works between pages but not on the initial loading. <html> <body onload="ajaxFunction('load_forums','-1','0','0','','3')"> <script language="javascript" type="text/javascript"> <!-- //Browser Support Code function ajaxFunction(action,id,logged_in,user_id,session_id,loader,field_one,field_two) { var ajaxRequest; try{ // Opera 8.0+, Firefox, Safari ajaxRequest = new XMLHttpRequest(); } catch (e){ // Internet Explorer Browsers try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ // Something went wrong alert("Your browser broke!"); return false; } } } ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 1) { if(loader=='0' || !loader) { var ajaxDisplay = document.getElementById('ajaxDiv'); loadtext="<img src='ajax-loader-lo.gif'> Please wait. Loading..." } if(loader=='1') { loadtext="<img src='ajax-loader-in.gif'> Initializing..."; } if(loader=='2') { loadtext="<img src='ajax-loader-up.gif'> Updating..."; } if(loader=='3') { loadtext="<img src='ajax-loader-lg.gif'> Logging In..."; } ajaxDisplay.innerHTML = loadtext; } if(ajaxRequest.readyState == 4) { if (ajaxRequest.status == 200) { var ajaxDisplay = document.getElementById('ajaxDiv'); ajaxDisplay.innerHTML = ajaxRequest.responseText; } if(ajaxRequest.status == 404) { var ajaxDisplay = document.getElementById('ajaxDiv'); ajaxDisplay.innerHTML = "Error. Service not found."; } if(ajaxRequest.status != 404 && ajaxRequest.status != 200) { var ajaxDisplay = document.getElementById('ajaxDiv'); ajaxDisplay.innerHTML = "Undefined internal error."; } } } var queryString = "?key-<?php echo md5(date("Y")) . "=" . md5(date("z")) . md5($_SERVER['REMOTE_ADDR']);?>&action=" + action; if(id) { queryString = queryString + "&id=" + id; } if(session_id) { queryString = queryString + "&session_id=" + session_id; } if(field_one) { queryString = queryString + "&field_one=" + field_one; } if(field_two) { queryString = queryString + "&field_two=" + field_two; } queryString = queryString + "&logged_in=" + logged_in queryString = queryString + "&user_id=" + logged_in ajaxRequest.open("GET", "gethint.php" + queryString, true); ajaxRequest.send(null); } //--> </script> <form name='myForm'></form> <div id='ajaxDiv'></div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/74834-solved-readystate-not-working/ Share on other sites More sharing options...
53329 Posted October 26, 2007 Author Share Posted October 26, 2007 Found it. I moved the div element (var ajaxDisplay = document.getElementById('ajaxDiv') into an if statement so it only worked if it was "loading". Link to comment https://forums.phpfreaks.com/topic/74834-solved-readystate-not-working/#findComment-378754 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.