I have written some code to fetch details from database according to the given id.
I am using ajax to help the ui. I can see the responseText in alert box but when i use it as reponseXML than it doesnt give me any child node

my server side and client side cod is as above if anyone knows the bug please help me i have tried a lot of effort to fix it.

Server Side

<?php

header('Content-Type: text/xml');
header("Cache-Control: no-cache, must-revalidate");
//A date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");


    // make database connection 
    $connection=makeConnection();
	$subTaskId=$_GET["subTaskId"];
	
	//if($subTaskId>0)
	//{

        $subtask_sql='Some SQL Query';
	$subtask_Result = mysql_query($subtask_sql,$connection);
	$xml_String='<?xml version="1.0" encoding="ISO-8859-1"?>
	<task>';
	while ($row_SubTask = mysql_fetch_array($subtask_Result))
                {
					$Id=$row_SubTask['TC_ID'];
					$Name=addSlashes($row_SubTask['TC_NAME']);
					$xml_String.='<SubTaskId>'.$Id.'</SubTaskId>';
					$xml_String.='<SubTaskName>'.$Name.'</SubTaskName>';
				}
	$xml_String.='</task>';
	echo $xml_String;
	//}
	mysql_close($con);
?>

At Client Side

function fetchSubtaskList(elem){
	if(document.getElementById('mainTaskCheck').checked && document.getElementById('subtaskCheck').checked)
	{
	var selectedOption=elem.options[elem.selectedIndex];
	xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
			{
				alert ("Browser does not support HTTP Request");
				return;
			} 
	var url="getFilteredSubtask.php";
	url=url+"?subTaskId="+selectedOption.value;
	url=url+"&sid="+Math.random();
	alert(url);
	xmlHttp.onreadystatechange=function(){
			if(xmlHttp.readyState == 4 || xmlHttp.readyState=="complete")
					{
					alert(xmlHttp.responseText);//here i can see the response text
					fillFileteredSubtask(xmlHttp.responseXML);
					}
	} 
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	
	}
}

function fillFileteredSubtask(xmlObject){
	if(xmlObject==null)
	{
		alert('xmlObject is null');
		return;
	}
	else
	{
	var target=document.getElementById('subTaskSelect');
		
		//empty the list 
		do
		{
		target.options[target.length-1]=null;
		}while(target.length!=0)


		var taskIdList=xmlObject.getElementsByTagName("SubTaskId");
		var taskValueList=xmlObject.getElementsByTagName("SubTaskName");
		var lngt=taskIdList.length;

		alert(lngt);//here i am unable to get the length of subtaskid but in reponse text it contains more than 3 entries. 

		for(i=0;i<lngt;i++){
		target.options[i] = new Option(taskValueList[i].childNodes[0].nodeValue,taskIdList[i].childNodes[0].nodeValue);
		}
	}
}

Recommended Answers

All 4 Replies

Hi,

in this case first run the server page independently with a valid value in querystring.

then check if this page displays a valid xml output.

I have tried that it gives xml which does not seems to valid xml. It is the problem. But in response Text everything looks fine. Is there any problem in casting text to xml Object ?

can you post the xml that you are getting

If you are using google chrome or mozila maybe you should get no object as return value from responseXML but if you try your code from internet explorer 7.0 you will see that your cod would work just fine

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.