Jump to content

[SOLVED] readyState not working


53329

Recommended Posts

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

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.