2 Replies - 1234 Views - Last Post: 13 February 2011 - 10:22 PM

#1 Delta_Echo  Icon User is offline

  • D.I.C Addict

Reputation: 5
  • View blog
  • Posts: 722
  • Joined: 24-October 07

This keyword : Interpreter cannot find object

Posted 13 February 2011 - 05:32 PM

I've been working on a javascript project that will let me rotate text (headlines) using xmlhttprequest. My code isn't complete but this is what i have so far:
function tr(elementId)
{
	this.eId = elementId;
	this.currentID = 0; // Corresponds to the current headline's mysql table ID. 
	
	// ...XML HTTP REQUEST specific stuff...
	
	this.xmlHttp = new XMLHttpRequest(); // My object wide xmlhttprequest object
	alert(this.xmlHttp.readyState);
	this.xmlHttpResponse = null; // The response document (XML v1) 
	
	this.xmlHttp.onreadystatechange = function ()
	{
		if( this.xmlHttp.readyState == 4 )
		{
			this.xmlHttpResponse = this.xmlHttp.responseXML;
			
			document.getElementById('hl').childNodes[0].nodeValue = 
				this.xmlHttpResponse.getElementsByTagName('hl')[0].childNodes[0].nodeValue;
			
			document.getElementsById('sl').childNodes[0].nodeValue =
				this.xmlHttpResponse.getelementsByTagName('sl')[0].childNodes[0].nodeValue;	
		}
	}
	
	this.next = function() {};
	this.last = function() {};
	this.buildUi = function()
	{
		var trContainer = document.createElement('div'); // Main container
			trContainer.setAttribute('id','trContainer');
		
		var lastButton = document.createElement('input'); 
			lastButton.setAttribute('type','button');
			lastButton.setAttribute('id','lsButton');
			lastButton.onclick = this.last;
			trContainer.appendChild(lastButton);
			
		var hl 			= document.createElement('div');
			hl.setAttribute('id','hl');
			trContainer.appendChild(hl);
			
		var sl			= document.createElement('div');
			sl.setAttribute('id','sl');
			trContainer.appendChild(sl);
			
		var nextButton  = document.createElement('input');
			nextButton.setAttribute('type','button');
			nextButton.setAttribute('id','nxButton');
			nextButton.onclick = this.next;
			trContainer.appendChild(nextButton);
			
		document.getElementById(this.eId).appendChild(trContainer); // Append everything to document
		
		this.xmlHttp.open('GET','tr.php',false);
		this.xmlHttp.send(null);
	};
	
	this.buildUi();
}



My problem is on line 14,
if( this.xmlHttp.readyState == 4 )
{



Chrome's Javascript console gives me:
tr.js:14 Uncaught TypeError: Cannot read property 'readyState' of undefined
tr.js:14 Uncaught TypeError: Cannot read property 'readyState' of undefined



I don't know whats wrong, I have an alert a few lines up with the same object and it works...

Any thoughts?

Thanks all

Is This A Good Question/Topic? 0
  • +

Replies To: This keyword : Interpreter cannot find object

#2 forest51690  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 58
  • View blog
  • Posts: 340
  • Joined: 20-March 09

Re: This keyword : Interpreter cannot find object

Posted 13 February 2011 - 07:21 PM

Yeah, my guess would be that insife the onreadystatechange function, the this keyword refers to this.xmlHttp. So you would write this.readyState.
Was This Post Helpful? 0
  • +
  • -

#3 Delta_Echo  Icon User is offline

  • D.I.C Addict

Reputation: 5
  • View blog
  • Posts: 722
  • Joined: 24-October 07

Re: This keyword : Interpreter cannot find object

Posted 13 February 2011 - 10:22 PM

View Postforest51690, on 13 February 2011 - 07:21 PM, said:

Yeah, my guess would be that insife the onreadystatechange function, the this keyword refers to this.xmlHttp. So you would write this.readyState.


Worked. Thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1