Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Troubleshooting the Simple Ajax Treeview

Posted on 2009-06-30
Medium Priority
Last Modified: 2012-08-14
Hi experts,

I downloaded some sample code to create a treeview using ajax and sql but I'm having difficulties getting it to work with my tables. I'm getting the error of a blank page. I downloaded the sample code from http://www.aspwebsolution.com/articles/xmlrep/ajax_treeview1/
I ran the query in the analyzer and it produced good results when i swapped out my userID for intParentId. I can't figure for the life of me where the origional parentId (mentorID) comes from in this script. Please look at the code to help me figure out what I'm doing wrong. Thanks!
Class TreeView
Private m_strMenuTable
Private m_strIdField
Private m_strParentIDField
Private m_strTextField
Private m_strConn
Public Property Let MenuTable(vNewValue): m_strMenuTable = vNewValue: End Property
Public Property Let IdField(vNewValue): m_strIdField = vNewValue: End Property
Public Property Let ParentIDField(vNewValue): m_strParentIdField = vNewValue: End Property
Public Property Let TextField(vNewValue): m_strTextField = vNewValue: End Property
Public Property Let ConnectionString(vNewValue): m_strConn = vNewValue: End Property
Private Sub Class_Initialize
	m_strMenuTable = "dbo.Members"
	m_strIdField = "userID"
	m_strParentIDField = "mentorID"
	m_strTextField = "lastName" & "," & "firstName"
End Sub
Private Sub Class_Terminate
	'Clear Objects 
End Sub
Public Function GetChildNodes(intParentId)
	Dim strSQL
	strSQL = "SELECT " & _
	m_strIdField & "," & _
	m_strTextField & "," & _
	"(SELECT COUNT(*) FROM " & m_strMenuTable & " B WHERE A."& m_strIdField &"=B." & m_strParentIDField & ") AS [HasChild]" & _
	" FROM " & m_strMenuTable &" A "& _
	" WHERE " & m_strParentIDField & " = " & intParentId
	Const strXsl = "treeview.xsl"
	GetChildNodes = GetDbXml(m_strConn,strSQL, strXsl)
End Function
Private Function GetDbXml(strConn,strSQL,strXsl)
	Dim strXml
	'test strsql
	strXml = GetDbString(strConn,strSql,"__COL","__ROW","__NULL")
	strXml = Replace(strXml,"&","&amp;")
	strXml = Replace(strXml,"<","&lt;")
	strXml = Replace(strXml,"__COL","</col><col>")
	strXml = Replace(strXml,"__ROW","</col></row><row><col>")
	strXml = Replace(strXml,"__NULL","")	
	strXml = "<rows><row><col>" & strXml & "</col></row></rows>"			
	strXml = Replace(strXml,"<row><col></col></row>","")
	If strXsl <> "" Then		
		Dim xml,xsl
		'Load XML
		if not loadXmlDoc(xml,strXml,"GetDb XML Source") then exit Function
		if not loadXmlDoc(xsl,strXsl,"GetDb XSL Stylesheet") then exit Function
		'Transform file
		strXml = xml.transformNode(xsl)
		Set xml = Nothing
		Set xsl = Nothing
	End If
	GetDbXml = strXml        	
End Function 
Private Function GetDbString(strConn,strSQL, ColumnDelimiter, RowDelimiter, NullExpr)
	Dim Conn 
	Set Conn = Server.CreateObject("ADODB.Connection")
	Conn.Open strConn
	Dim RS
	Set RS = Conn.Execute(strSql)		
	If Not RS.EOF Then		
		GetDbString = RS.GetString(,, ColumnDelimiter, RowDelimiter, NullExpr) 
	End If	
	Set RS = Nothing
	Set Conn = Nothing					
End function
Private Function LoadXmlDoc(ByRef xmldoc, ByVal source, ByVal title)
	If Trim(source) = "" Then
		Exit Function
	End If
	Set xmldoc = Server.CreateObject("Microsoft.XMLDOM")
	If Left(source,7) = "http://" Then
		xmldoc.setProperty "ServerHTTPRequest", True
		xmldoc.async =  False
		'set xmldoc = Server.CreateObject("Microsoft.XMLDOM")
		xmldoc.async = false
		If InStr(source,"<") Then 
			if InStr(source,":\") = 0 then source = Server.MapPath(source)
			'test source
		end if
	End If
	if xmldoc.parseError.errorcode <> 0 then
		'"<error code='" & xmldoc.parseError.errorcode & "'><![CDATA[" & xmldoc.parseError.reason & "]]></error>"
		LoadXmlDoc = True
	end if		
End Function
End Class
<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
	<xsl:output method="xml" indent="no" omit-xml-declaration="yes" />
	<xsl:variable name="images.folder" select="'images'" />	
	<xsl:template match="/">		
			<xsl:apply-templates  />
	<xsl:template match="row">
		<xsl:variable name="menu.id" select="col[1]" />
		<xsl:variable name="text" select="col[2]" />
		<xsl:variable name="has.child" select="col[3]" />
		<table border="0" cellpadding="0" cellspacing="0">
				<td rowspan="2" width="10" valign="top">
					<img id="I{$menu.id}">
							<xsl:when test="number($has.child) &gt; 0">
								<xsl:attribute name="src">
									<xsl:value-of select="concat($images.folder,'/plus.gif')"/>
								<xsl:attribute name="onclick">
									<xsl:value-of select="concat('loadItems(',$menu.id,')')"/>
								<xsl:attribute name="src">
									<xsl:value-of select="concat($images.folder,'/dot.gif')"/>
				<td nowrap="true">
					<a href="javascript:alert({$menu.id});">
						<xsl:value-of select="$text" />						
				<td id="C{$menu.id}" style="display:none;"></td>
// global request and XML document objects
var req;
// retrieve XML document (reusable generic function);
// parameter is URL string (relative or complete) to
// an .xml file whose Content-Type is a valid XML
// type, such as text/xml; XML source must be from
// same domain as HTML file
function loadXMLDoc(url) {	
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        //isIE = true;
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
// handle onreadystatechange event of req object
function processReqChange(){
	// only if req shows "complete"
	if (req.readyState == 4) {
		// only if "OK"
		if (req.status == 200) {		
			// ...processing statements go here...
			response  = req.responseXML.documentElement;
			method =
			//result = response.getElementsByTagName('result')[0].firstChild.data;
			var start = req.responseText.indexOf('<result>') + 8
			var stop = req.responseText.indexOf('</result>')
			result = req.responseText.substring(start,stop);
			eval(method + '(\'\', result)');
		} else {
			alert("There was a problem retrieving the XML data:\n" + req.statusText);
var current_el = null;
var loading;
var began = false      
function getItems(input, response){	
	if (response != ''){ 		
	    // Response mode	
        current_el.innerHTML = response;
        loading.style.display = 'none'
		// Input mode			
		var url  = "process_request.asp?p=" + input + "&hash=" + Math.random();
function loadItems(id,c){ 
	var img = null;
		c = "C" + id;
		img = document.getElementById("I"+id);
	current_el = document.getElementById(c);
	if(current_el.style.display == 'none'){
		current_el.style.display = ''
		if(img)img.src = "images/minus.gif";
		current_el.style.display = 'none'
		if(img)img.src = "images/plus.gif";
	if(current_el.innerHTML == ''){
		loading.style.display = ''
function buildTree(id){
	if (!began){
		loading = document.getElementById("Loading")
		document.getElementById(id).style.display = 'none';
		began = true;
<%Option Explicit%>
<!--#include file="treeview.asp"-->
Sub GetItems(parentId)
	Dim strConn,strTable
	strTable = "dbo.Members"
	strConn = "Provider=sqloledb; Data Source=xxx.db.3731644.hostedresource.com; Initial Catalog=xxx; User ID=xxx; Password=xxx"
	Dim tv
	Set tv = New TreeView
	tv.MenuTable = strTable
	tv.ConnectionString = strConn
	Response.Write tv.GetChildNodes(MM_userID)
	Set tv = Nothing
End Sub
Dim parentId:parentId = Request("p") 
If parentId="" Then parentId = 0
Response.ContentType = "text/xml"
<%= "<?xml version='1.0' encoding='ISO-8859-1'  standalone='yes'?>" %>
  <result><% Call GetItems(parentId) %></result>

Open in new window

Question by:GMMC_man
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 29

Accepted Solution

Badotz earned 2000 total points
ID: 24745864
This is not a question, it is an expression of need for application development, and for those kinds of needs you should hire a developer.

We are not paid to do development here at EE -- we are just volunteers who answer questions for points and the occasional T-shirt.

Perhaps Rent-A-Coder or a similar service can help you.

Best of luck with your project.

Author Comment

ID: 24746733
Ok - thanks.

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This article discusses how to implement server side field validation and display customized error messages to the client.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question