/    Sign up×
Community /Pin to ProfileBookmark

Ajax returning null

[code]<html>
<head>

</head>
<body>
<script type=’text/javascript’>
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject(“Msxml2.XMLHTTP”);
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject(“Microsoft.XMLHTTP”);
}
catch (e)
{
alert(“Your browser does not support AJAX!”);
}
}
}
xmlHttp.open(“GET”,”ajaxtext.php”,true);
xmlHttp.send(null);
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
xmlObjectThing = xmlHttp.responseXML;
alert(xmlObjectThing.getElementsByTagName(“firstname”)[0].nodeValue)
}
}
</script>
</body>
</html>[/code]

ajaxtext.php

[code]<?php

header(‘Content-Type: text/xml’);
header(“Cache-Control: no-cache, must-revalidate”);

echo ‘<?xml version=”1.0″ encoding=”ISO-8859-1″?>
<person>’;

echo “<firstname>head</firstname>”;
echo “<lastname>stupid</lastname>”;
echo “<age>900</age>”;
echo “<hometown>town</hometown>”;
echo “<job>crap</job>”;
echo “</person>”;
?>[/code]

Ok so I have that but it keeps returning null for nodeValue on the element firstname….. I have looked all through places searched google done all that stuff and I can’t find an answer for my problem….. I mean seriously why is it so hard for this to work

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@DokSep 29.2008 — If xmlObjectThing is not valid XML markup it will be null. Have you tried outputting the reponse to a browser and validating it?
Copy linkTweet thisAlerts:
@posiden5665authorSep 29.2008 — Well both of these return no errors: http://w3schools.com/xml/xml_validator.asp

but this one is throwing an error http://www.validome.org/xml/validate/

so i dont know what the hell to think
Copy linkTweet thisAlerts:
@posiden5665authorSep 30.2008 — Comon someone has to have an answer for this... I really need this to work
×

Success!

Help @posiden5665 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...