PDA

View Full Version : getElementByTegName is undefined error


aartik
12-15-2009, 04:45 AM
I saw the previous posts on this, but it did not seem of much help.
I really need help on this one.

Its a very simple ajax type of application that I am trying to run with html, js, php and a xml file.

html has a drop down which on selection calls JS, which calls a php file to display xml data.
my purpose is to just group that xml data for formatting for displaying.

I am tryin to get the elements by tagname to get them to be displayed in one div in html with some formatting.

here is the JS code:

// JavaScript Document

var xmlhttp

function showResume(str)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var url="getresume.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function stateChanged()
{
if (xmlhttp.readyState==4)
{
//xmlDoc=xmlhttp.responseXML;
var xmlDoc=xmlhttp.responseXML.documentElement;
document.getElementById("name").innerHTML= xmlDoc.getElementsByTagName("NAME")[0].childNodes[0].nodeValue;
//document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
//document.getElementById("education").innerHTML=xmlhttp.responseText;
}
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}

PHP code:

<?php
header('Content-Type: text/xml');
$q=$_GET["q"];

$xmlobj = simplexml_load_file('resume.xml');


foreach ($xmlobj->RESUME as $RESUME)
{
$name = htmlspecialchars($RESUME->NAME);

if ($name == $q) {

$name = htmlspecialchars($RESUME->NAME);
$address1 = htmlspecialchars($RESUME->ADDRESS1);
$address2 = htmlspecialchars($RESUME->ADDRESS2);
$city = htmlspecialchars($RESUME->CITY);
$state = htmlspecialchars($RESUME->STATE);
$zipcode = htmlspecialchars($RESUME->ZIPCODE);



}
echo $xmlobj->saveXML();
}
?>

XML:

<?xml version="1.0" encoding="utf-8"?>

<RESUME>

<NAME>Aarti Keshwani</NAME>
<ADDRESS1>2400 Virginia Ave NW</ADDRESS1>
<ADDRESS2>Apt C1126</ADDRESS2>
<CITY>Washington</CITY>
<STATE>DC</STATE>
<ZIPCODE>20037</ZIPCODE>
<PHONENUM>832-474-7151</PHONENUM>
<EMAIL>aartikeshwani@hotmail.com</EMAIL>

<EDUCATION>

<SCHOOL>
<SCHOOLNAME>The George Washington University</SCHOOLNAME>
<LOCATION>Washington, DC</LOCATION>
<DEGREE>Master of Science in Information Systems Technology</DEGREE>
<MAJOR>Information Systems Development</MAJOR>
<PERIOD>
<FROM>Aug 2008</FROM>
<TO>May 2010</TO>
</PERIOD>
<ACHIEVEMENTS>
<DESCRIPTION>Relevant Projects: Designed and built an application for self-checkout kiosks using Microsoft .NET language C# to improve the usability and efficiency of the system</DESCRIPTION>
</ACHIEVEMENTS>
<WEBSITE>School Website:The George Washington University</WEBSITE>
</SCHOOL>

<SCHOOL>
<SCHOOLNAME>Vivekananda Education Society's Institute of Technology</SCHOOLNAME>
<LOCATION>Mumbai,India</LOCATION>
<DEGREE>Bachelor of Engineering</DEGREE>
<MAJOR>Computer</MAJOR>
<PERIOD>
<FROM>Sept 2003</FROM>
<TO>May 2007</TO>
</PERIOD>
<ACHIEVEMENTS>
<DESCRIPTION>IEEE Award for the best technical paper on 'Genetic Algorithm in Data Mining'</DESCRIPTION>
</ACHIEVEMENTS>
<WEBSITE>School Website:Vivekananda Education Society's Institute of Technology</WEBSITE>
</SCHOOL>

</EDUCATION>

<JOBS>
<EMPLOYER>

<COMPANYNAME>Accenture Services Pvt Ltd</COMPANYNAME>
<LOCATION>Mumbai,India</LOCATION>
<JOBTITLE>Junior Software Engineer</JOBTITLE>
<PERIOD>
<FROM>July 2007</FROM>
<TO>June 2008</TO>
</PERIOD>
<DESCRIPTION>
<ROLE>Completed four-month domain training program and acquired technical knowledge in CSharp, C++, SQL and UNIX Programming</ROLE>
<ROLE>Was one amongst the 15 to be selected for working with Avanade team which is a Microsoft partner for delivering customer solutions built on Microsoft technology</ROLE>
</DESCRIPTION>
</EMPLOYER>
</JOBS>

<SKILLS>
<SKILL>ASP.NET</SKILL>
<SKILL>C++</SKILL>
<SKILL>HTML</SKILL>
<SKILL>PL/SQL</SKILL>
</SKILLS>

</RESUME>


I dont know where am i making a mistake?

pleassseeee someone help

Kor
12-17-2009, 11:31 AM
Check also the objects's status as well:

if (xmlhttp.readyState==4){
if(xmlhttp.status==200){
...
}
}