comissioner
Technical User
Hello to all!
Im new to js and ive run into difficulty
I have a html page with 2 parts of javascript.
1. this is to retrieve text
2. This is to retrieve data from an xml file
I have 2 functions in an external js file but the problem is only 1. works
Im using a xmlhttpRequest.
Here is the js function code
Could some one help me out? Ive literally spent hours on this and I cant get it to work properly. Each part works fine on their own but when I try to put them together i have difficulties.
Any help would be greatly appreciated!
Im new to js and ive run into difficulty
I have a html page with 2 parts of javascript.
1. this is to retrieve text
2. This is to retrieve data from an xml file
I have 2 functions in an external js file but the problem is only 1. works
Im using a xmlhttpRequest.
Here is the js function code
Code:
function loadScript(scriptURL)
{
var newScript = document.createElement("script");
newScript.src = scriptURL;
document.body.appendChild(newScript);
}
function createXMLHttpRequest() {
xmlReq = null;
if(window.XMLHttpRequest) xmlReq = new XMLHttpRequest();
else if(window.ActiveXObject) xmlReq = new ActiveXObject("Microsoft.XMLHTTP");
if(xmlReq==null) return; // Failed to create the request
}
function loadData(URL)
{
// Anonymous function to handle changed request states
xmlReq.onreadystatechange = loadData(URL)
{
switch(xmlReq.readyState)
{
case 0: // Uninitialized
break;
case 1: // Loading
break;
case 2: // Loaded
break;
case 3: // Interactive
break;
case 4: // Done!
// Retrieve the data between the <quote> tags
doSomethingWithData(xmlReq.responseXML.getElementsByTagName('quote')[0].firstChild.data);
break;
default:
break;
}
}
// Make the request
xmlReq.open ('GET', URL, true);
xmlReq.send (null);
}
function loadXML(url)
{
xmlReq2 = null;
if(window.XMLHttpRequest) xmlReq2 = new XMLHttpRequest();
else if(window.ActiveXObject) xmlReq2 = new ActiveXObject("Microsoft.XMLHTTP");
if(xmlReq2==null) return; // Failed to create the request
// Anonymous function to handle changed request states
xmlReq2.onreadystatechange = loadXML()
{
switch(xmlReq2.readyState)
{
case 0: // Uninitialized
break;
case 1: // Loading
break;
case 2: // Loaded
break;
case 3: // Interactive
break;
case 4: // Done!
// Retrieve the data between the <quote> tags
doSomethingWithXml(xmlReq2.responseXML.getElementsByTagName('quote')[0].firstChild.data);
break;
default:
break;
}
}
// Make the request
xmlReq2.open ('GET', URL, true);
xmlReq2.send (null);
}
Any help would be greatly appreciated!