/*
This is the ajax document, which hold the functions to do a ajax call
the the php file that generates the XML file.
*/
function httpFind() {
var http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');
// See note below about this line
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}
return http_request;
}
function makeXml(){
var dir = document.getElementById('dir').value;
var fil = document.getElementById('filnavn').value;
if (fil == "*"){
fil = "[star]";
}
url = 'xml.php?dir=' + dir + '&fil=' + fil;
http_request = httpFind();
http_request.onreadystatechange = function() { showXml(http_request); };
http_request.open('GET', url, true);
http_request.send(null);
}
function showXml(http_request, hvilken){
if (http_request.readyState == 4) {
if (http_request.status == 200) {
var xmldoc = http_request.responseXML;
var root_node = xmldoc.getElementsByTagName('xmlresponse')[0];
var forste = 0;
document.getElementById('filhvor').innerHTML = '<div id="typetop">Type</div><div id="nametop">Name</div><div id="pathtop">Path</div>';
var tal = 1;
for (var iNode = 0; iNode < root_node.childNodes.length; iNode++) {
var node = root_node.childNodes.item(iNode);
for (i = 0; i < node.childNodes.length; i++) {
var sibling = node.childNodes.item(i);
if (sibling.data == "Nothing found"){
document.getElementById('filhvor').innerHTML += sibling.data + "<br>";
} else {
if (tal == 1){
document.getElementById('filhvor').innerHTML += '<div class="type">' + sibling.data + '</div>';
tal = 2;
} else if (tal == 2){
document.getElementById('filhvor').innerHTML += '<div class="name">' + sibling.data + '</div>';
tal = 3;
} else {
document.getElementById('filhvor').innerHTML += '<div class="path">' + sibling.data + '</div>';
tal = 1;
}
}
}
}
} else {
alert('There was a problem with the request.');
}
}
} |