AJAX Wrapper Class

Faulty Custom AJAX Wrapper Class

Page 1 of 1

0 Replies - 921 Views - Last Post: 14 August 2009 - 03:40 AM

#1 qqwetiqewq  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 26-September 07

AJAX Wrapper Class

Post icon  Posted 14 August 2009 - 03:40 AM

I'm trying to make a simple AJAX wrapper class, and of course have come across a problem.

I am using xampp on my pc, with just index.php and AJAX.js extra in the htdocs folder.

This is the HTML from http://127.0.0.1/
<html>
	<head>
		<title>
			Chess
		</title>
		<script src='AJAX.js'> </script>
	</head>
	<body onload="getData('http://127.0.0.1/?page=1');">
		Default
	</body>
</html>


Which is exactly as expected.

The java script:
function newAJAXWrapper()
{
	this.AJAXControl;
	
	this.sendOffRequest = sendOffRequest;
		
	alert('lol');
	
	function stateChanged()
	{
		alert(this.AJAXControl.responseText);
	}
	
	function sendOffRequest(url)
	{
		this.AJAXControl = null;
		try
		{
			  // Firefox, Opera 8.0+, Safari
			  this.AJAXControl = new XMLHttpRequest();
		}
		catch (e)
		{
			// Internet Explorer
			try
			{
				this.AJAXControl = new ActiveXObject("Msxml2.XMLHTTP");
			}
			
			  catch (e)
			{
				try
				{
					this.AJAXControl = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e)
				{
					alert("Your browser does not support AJAX!");
					return false;
				}
			}
		}
		
		this.AJAXControl.onreadystatechange = this.stateChanged;
		
		try
		{	
			this.AJAXControl.open("GET", url, true);
			this.AJAXControl.send(null);
			alert(url);
		}
		catch(err)
		{
			alert("Error connecting to server");
		}
	}
}

var theWrapper;

function getData(url)
{
	theWrapper = new newAJAXWrapper();
	theWrapper.sendOffRequest(url);
}



When the page has loaded, i get two messages:
1) lol
2) http://127.0.0.1/?page=1

I put the URL in the address bar and also get what I expect.
So why dont I get the third message with the response?

Many thanks :)

Is This A Good Question/Topic? 0
  • +

Page 1 of 1