Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation AJAX and XML Error

    I am currently working on a website that involves getting commands and data via ajax from a server.

    IE 7, 8 have an error saying that childNodes.0 is null or not an object on line 86 char 3 of the js script file I have... any help would be great
    I have verified that it is returned as an xml document and that the xml is valid


    ajax file:
    Code:
    function dAjax()
    {
    	this.method = NULL;
    	this.param = '';
    	this.async = true;
    	this.url = '';
    	this.status = NULL;
    	this.req = NULL;
    	this.statusText = '';
    	this.postData = NULL;
    	this.readyState = NULL;
    	this.responseText = NULL;
    	this.item = "";
    }
    dAjax.init = function ()
    {
    	if(!this.req)
    	{
    		try
    		{
    			this.req = new XMLHttpRequest();
    		}
    		catch (e)
    		{
    			try
    			{
    				this.req = new ActiveXObject('MSXML2.XMLHTTP');
    			}
    			catch (e)
    			{
    				try
    				{
    					this.req = new ActiveXObject('Microsoft.XMLHTTP');
    				}
    				catch (e)
    				{
    					return false;
    				}
    			}
    		}
    	}
    	return this.req;
    };
    
    
    
    dAjax.doQuery = function (element)
    {
    	if(!this.init())
    	{
    		this.debug.errorCode += "\nError Code: init1. Could not create dAjax Module\n";
    		alert("Your Browser cannot run the application.\nPlease Return to the homepage for alternatives");
    		return;
    	}
    	
    	var self = this;
    	var req = this.req
    	if(this.method == "POST") {
    		req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    		req.setRequestHeader("Content-length", this.param.length);
    		req.setRequestHeader("Connection", "close");
    	}
    	if(this.params) {
    		req.open(this.method, this.url+this.params, this.async);
    	} else req.open(this.method, this.url, this.async);
    	req.onreadystatechange = function() { 
    		self = this;
    		if(self.readyState == 4) {
    			dAjax.response( self.responseXML, self.status, self.mimeType, element);
    		}
    	};
    if(!req.onreadystatechange) {
    	req.onload = function() {
    		self = this;
    		if(this.readyState == 4) {
    			dAjax.response( self.responseXML, self.status, self.mimeType, element);
    		}
    	};
    }
    	this.req.send(this.postData);
    	//dAjax.response(this.req.responseText,this.req.status,this.req.mimeType,'me')
    };
    
    dAjax.response = function (response, status, mimeType, element)
    {
    	if(status>=200&&status<400) {
    		var root = response.childNodes[0];
    		if(root.childNodes[0].getAttribute('id')=="none") {
    			window.document.title += " - "+root.getAttribute('name');
    			dAjax.item = root.getAttribute('id');
    			document.getElementById('item').innerHTML = "<b style='font-size:20px;'>"+root.getAttribute('name');+"</b>";
    			var type1 = new Array();
    			var type2 = new Array();
    			for (var iNode = 1; iNode < root.childNodes.length; iNode++) {
    				var node = root.childNodes[iNode];
    				type = node.childNodes[0].textContent;
    				if(type=="1") {
    					content = node.childNodes[1].textContent;
    					rating = node.childNodes[2].textContent;
    					id = node.getAttribute("id");
    					var array = new Array(content,rating,id);
    					i=0;
    					while(type1[i]!=null) {
    						i++;
    					}
    					type1[i] = array;
    				} else {
    					content = node.childNodes[1].textContent;
    					rating = node.childNodes[2].textContent;
    					id = node.getAttribute("id");
    					i=0;
    					while(type2[i]!=null) {
    						i++;
    					}
    					var array = new Array(content,rating,id);
    					type2[i] = array
    				}
    
    			}
    			var str = "<tr><td id='type'><img src='./images/neg.gif' width='100' /></td><td id='type'><img src='./images/pos.png'  width='50' /></td></tr>";
    			if(type2.length>=type1.length) {
    				for(i=0;i<type2.length;i++) {
    					t = type1[i];
    					t2 = type2[i];
    					te1 = null;
    					te2 = null;
    					if(t!=null) {te1 = t[0]+"<br /><span class='progressBar' id='"+t[2]+"'>"+t[1]+"%</span> <a href='#' name='"+t[2]+"' onclick='dAjax.params=\"?action=voteItem&itemID=\"+dAjax.item+\"&commentID=\"+this.name+\"&type=2\"; dAjax.doQuery(\"item\");'><img src='./images/up.jpg' height='20' border='0' /></a><a href='#' name='"+t[2]+"' onclick='dAjax.params=\"?action=voteItem&itemID=\"+dAjax.item+\"&commentID=\"+this.name+\"&type=1\"; dAjax.doQuery(\"item\");'><img src='./images/down.jpg' height='20' border='0' /></a>";}
    					if(t2!=null) {te2 = t2[0]+"<br /><span class='progressBar'  id='"+t2[2]+"'>"+t2[1]+"%</span> <a href='#' name='"+t2[2]+"' onclick='dAjax.params=\"?action=voteItem&itemID=\"+dAjax.item+\"&commentID=\"+this.name+\"&type=2\"; dAjax.doQuery(\"item\");'><img src='./images/up.jpg' height='20' border='0' /></a><a href='#' name='"+t2[2]+"' onclick='dAjax.params=\"?action=voteItem&itemID=\"+dAjax.item+\"&commentID=\"+this.name+\"&type=1\"; dAjax.doQuery(\"item\");'><img src='./images/down.jpg' height='20' border='0' /></a>";}
    					if(!(te1==null) && !(te2==null)) {str += "<tr><td>"+te2+"</td><td>"+te1+"</td></tr>";}
    					else if(te1==null && te2!=null) {str += "<tr><td>&nbsp;</td><td>"+te2+"</td>";}
    					else {str += "<tr><td>"+te1+"</td><td>&nbsp;</td>";}
    				}
    			} else {
    				for(i=0;i<type1.length;i++) {
    					t = type1[i];
    					t2 = type2[i];
    					te1 = null;
    					te2 = null;
    					if(t!=null) {te1 = t[0]+"<br /><span class='progressBar' id='"+t[2]+"'>"+t[1]+"%</span> <a href='#' name='"+t[2]+"' onclick='dAjax.params=\"?action=voteItem&itemID=\"+dAjax.item+\"&commentID=\"+this.name+\"&type=2\"; dAjax.doQuery(\"item\");'><img src='./images/up.jpg' height='20' border='0' /></a><a href='#' name='"+t[2]+"' onclick='dAjax.params=\"?action=voteItem&itemID=\"+dAjax.item+\"&commentID=\"+this.name+\"&type=1\"; dAjax.doQuery(\"item\");'><img src='./images/down.jpg' height='20' border='0' /></a>";}
    					if(t2!=null) {te2 = t2[0]+"<br /><span class='progressBar'  id='"+t2[2]+"'>"+t2[1]+"%</span> <a href='#' name='"+t[2]+"' onclick='dAjax.params=\"?action=voteItem&itemID=\"+dAjax.item+\"&commentID=\"+this.name+\"&type=2\"; dAjax.doQuery(\"item\");'><img src='./images/up.jpg' height='20' border='0' /></a><a href='#' name='"+t2[2]+"' onclick='dAjax.params=\"?action=voteItem&itemID=\"+dAjax.item+\"&commentID=\"+this.name+\"&type=1\"; dAjax.doQuery(\"item\");'><img src='./images/down.jpg' height='20' border='0' /></a>";}
    					if(!(te1==null) && !(te2==null)) {str += "<tr><td>"+te2+"</td><td>"+te1+"</td></tr>";}
    					else if(te1==null && te2!=null) {str += "<tr><td>&nbsp;</td><td>"+te2+"</td>";}
    					else {str += "<tr><td>"+te1+"</td><td>&nbsp;</td>";}
    				}
    			}
    			document.getElementById('comments').innerHTML = str;
    			initProgressBarHandler();
    			return true;
    		} else {
    			switch(root.childNodes[0].getAttribute('id')) {
    				case 'alert':
    				alert(root.childNodes[0].childNodes[0].textContent);
    				break;
    			}
    		}
    	}
    	else {
    		document.getElementById('comments').innerHTML = "<tr><td colspan=\"2\">There was an error loading the page</td></tr>";
    	}
    };
    
    dAjax.abort = function ()
    {
    	if(this.init)
    	{
    		this.onreadystatechange = null;
    		this.req.abort();
    		this.req = null;
    	}
    };
    here is the response xml from the server:
    Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <item id='1' name='Welcome To Pro's And Con's'><command id='none'><param></param></command><comment id='1224'><type>1</type><content>See below for some of our latest added items!</content><rating>100</rating></comment><comment id='1221'><type>2</type><content><![CDATA[
    Welcome to prosandcons....<br />
    This site is all about your opinion about the issues and what matters.<br />
    Add a topic or share your opinion with other people about they're topics.<br />
    <br />
    All The Best<br />
    ]]></content><rating>100</rating></comment></item>
    The site can be found at http://prosandcons.djcentric.com/template.html
    The dynamic xml file is http://prosandcons.djcentric.com/
    The javscript file (which is updated continually is at http://prosandcons.djcentric.com/dAjax.js
    Last edited by jaitaiwan; 01-30-2009 at 12:37 AM. Reason: Adding information for quick review

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    Well you should not be using self as a variable name, use "that, ref, foo, etc".

    I tried to run it and IE7 never makes the call for the XML document. An error occurs before that.

    Code:
    Line: 72
    Error: Object doesn't support this property or method
    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I have edited the code above to include the fix for the unsupported method...
    I believe onload is required for ff3 to load data


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •