Ok
Idk where the problem is, i tried w3schools example and just altered the tag names to my xml file and changed the function name as well - didn't work, neither did some example tutorial i tried
I changed the code here is how it looks like - AJAX: moje.js
var xmlHttp = createXmlHttpRequestObject();
//create object
function createXmlHttpRequestObject() {
var xmlHttp;
if (window.XMLHttpRequest){
xmlHttp = new XLHttpRequest();
} else {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlHttp;
}
//called onload
function process() {
if(xmlHttp) {
try{
xmlHttp.open("GET", "webdesign.xml", true);
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.send(null);
}
catch(e) {
alert(e.toString());
}
}
//when state changes
function handleStateChanges() {
id(xmlHttp.readyState==4) {
if(xmlHttp.status==200) {
try {
handleResponse();
}
catch(e) {
alert(e.toString());
}
} else {
alert(xmlHttp.statusText);
}
}
}
//handle the response from the server
function handleResponse() {
var xmlResponse = xmlHttp.responseXML;
root = xmlResponse.documentElement;
articles = root.getElementsByTagName("TITLE");
authors = root.getElementsByTagName("AUTHOR");
var stuff = "";
for (var i=0; i<articles.length; i++) {
stuff = articles.item(i).firstChild.data + " - " + authors.item(i).firstChild.data + "<br/>";
}
super2 = document.getElementByID("super2");
super2.innerHtml = stuff;
}
The XML: what im trying to do is to loop throug it and display all authors and titles in an article in my html: webdesign.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<RESPONSE>
<TOPICS>
<ARTICLE>
<TITLE>The Lean UX Manifesto: Principle-Driven Design</TITLE>
<AUTHOR>Anthony Viviano</AUTHOR>
<YEAR>2014</YEAR>
<TEXT>My colleague Ajay and I have been working at incorporating lean UX at the enterprise level for over two years. In studying it, I find that there is a temptation to lay down rules, and if the rules arent followed. well, then, you cant call it lean UX. At the end of the day, though, some lean UX is better than none.</TEXT>
</ARTICLE>
<ARTICLE>
<TITLE>Killer Responsive Layouts With CSS Regions</TITLE>
<AUTHOR>CJ Gammon<AUTHOR>
<YEAR>2013</YEAR>
<TEXT>As Web designers, we are largely constrained by the layout features available to us. Content placed inside a container will often naturally extend the container vertically, wrapping the content. If a design requires elements to remain a certain height, then our options are limited. In these cases, we can only add a scroll bar or hide the overflow. The CSS Regions specification provides a new option.</TEXT>
</ARTICLE>
<ARTICLE>
<TITLE>Original And Innovative Web Layouts</TITLE>
<AUTHOR>Shavaughn Haack</AUTHOR>
<YEAR>2013</YEAR>
<TEXT>The layout is the foundation of your website. It guides the user through the sections and tells them what is most important. It also sets the aesthetic of the website. Therefore, you need to carefully think through how you lay out content.</TEXT>
</ARTICLE>
</TOPICS>
</RESPONSE>
And the html element:
<article id='super2'>
<button onclick="process()">Get XML data</button>
</article>
So im basically calling the process function here, it should return the data but nothing happens
I have the javascript file attached to html <script type="text/javascript" src="moje.js"></script> there should be no problem