Have I missed something in my code?

0 Jordan Walker · May 31, 2015
I'm getting an error that says that process is not defined however it looks like I have. Please help!: 

var xmlHttp = createXmlHttpRequestObject();

//create object

function createXmlHttpRequestObject(){
var xmlHttp;
if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}else{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlHttp;
}
//called On Load
function process(){
if(xmlHttp){
try{
xmlHttp.open("GET", "Ajax5.xml", true);
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.send(null);
}catch(e){
alert(e.toString());
}
}
}
//when state changes
function handleStateChange(){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
try{
handleResponse();
}catch(e){
alert(e.toString());
}
}else{
alert(xmlHttp.statusText);
}
}
}
//handle response from the server
function handleResponse(){
var xmlResponse = xmlHttp.responseXML;
root = xmlResponse.documentElement;
names = root.getElementsByTagName("name");
ssns = root.getElementsByTagName("ssn");

var stuff += "";
for(var i=0; i<names.length; i++){
stuff = names.item(i).firstChild.data + " - " + ssns.item(1).firstChild.data +  "<br/> ";
}

theD = document.getElementById(theD);
theD.innerHTML = stuff; 

}

Post a Reply

Replies

Oldest  Newest  Rating
0 Superman HC · May 31, 2015
3 mistakes of your code:

1. var stuff = ""; (during initialization.. no need for +)

2. stuff+= names.item(i).firstChild.data + " - " + ssns.item(1).firstChild.data + "<br/> "; (here is d need of +)

3. in the second last line double quotes should be there...

     theD = document.getElementById("theD");
+1 William Frost · May 31, 2015
Just a question. Have you tried to debug your code? Or use any dev tools?
Well those are two question. deal with that 8-)
0 Jordan Walker · June 1, 2015
Thank you guys! 
  • 1

Javascript

106,956 followers
About

A scripting language that is added to standard HTML to create interactive effects, apps, games for the browser.

Links
Moderators