C
chofer02
Hallo, hab wieder ein problem mit meinem Code:
Christoph
- folgende if Anweisung arbeitet falsch: xmlhttp.readyState == 4 && xmlhttp.status == 200
- bei der xml abfrage link.href erhalte ich nur [OBJECT]
Christoph
Code:
var xmlhttp = false;
if (window.xmlhttprequest)
{
xmlhttp = new xmlhttprequest ();
xmlhttp.overrideMimeType('text/xml');
}
else if (window.ActiveXObject)
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
function delstat()
{
document.getElementById('s_status').innerHTML = '';
}
function srch()
{
var e_query = document.getElementById('query').value;
if (e_query == "")
{
document.getElementById('result').innerHMTL = ' ';
}
if (e_query != "")
{
document.getElementById('prog').innerHMTL = 'Searching in progress...';
document.getElementById('s_status').innerHTML = '<img src="search.gif">';
var url = 'search.php?q=' + e_query;
xmlhttp.open('GET',url,true);
xmlhttp.onreadystatechange = function ()
{
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
var XMLDokument;
var i;
if (navigator.userAgent.indexOf("MSIE")>-1)
{
XMLDokument = new ActiveXObject("microsoft.xmldom");
XMLDokument.async = false;
XMLDokument.load(xmlhttp.responseXML);
}
if (navigator.userAgent.indexOf("Netscape")>-1)
{
XMLDokument = document.implementation.createDocument("", "", null);
XMLDokument.load(xmlhttp.responseXML);
}
{
var x = XMLDokument.getElementsByTagName('text');
var statistik = "Ihre Suchanfrage ergab "+x.length+" Treffer!";
document.getElementById('writeroot').innerHTML = statistik;
var x = XMLDokument.getElementsByTagName('text');
var newEl = document.createElement('P');
for (i=0;i<x.length;i++)
{
if (x[i].childNodes[0].nodeType != 1 && x[i].childNodes[1].nodeType != 1) continue;
var container = document.createElement('p');
var link = document.createElement("a");
var link_text = document.createTextNode(x[i].childNodes[0].firstChild.nodeValue);
link.href = document.createTextNode(x[i].childNodes[1].firstChild.nodeValue);
link.target = "_blank";
link.appendChild(link_text);
container.appendChild(link);
newEl.appendChild(container);
}
document.getElementById('result').appendChild(newEl);
}
setTimeout("delstat()",700);
}
else
{
document.getElementById('result').innerHTML = 'Error: Search Failed!';
setTimeout("delstat()",700);
}
}
xmlhttp.send(null);
}
}