Javascript + DOM + browsers = problems!
The DOM methods to get the node name are different for IE and FF. For FireFox, the 'tagName' method isn't working for IE (+6). For IE i had to use 'nodeName'. Wierd but that's how is it!
The xml is similar to:
<?xml version="1.0"?>
<root version="-live-" date="2008-11-21T14:45:24">
<item>
<foo/>
</item>
</root>
To fill the form field name 'field1' with the xml ajax response object 'resp' (XMLHttpRequest) above,
- for IE: document.getElementById("form").field1.value=resp.getElementsByTagName('root')[0].childNodes[1].nodeName;
- for 'other' browsers: document.getElementById("form").field1.value=resp.getElementsByTagName('root')[0].childNodes[1].tagName;
xmlHttp=GetXmlHttpObject()
var url="livesearch.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("anyId"). innerHTML=xmlHttp.responseText;
}
}
A nice thing that i didn't heard about since yesterday was to use Javascript debugger! And this was my salvation. I put a link where i found the useful information:
http://www.jonathanboutelle.com/mt/archives/2006/01/howto_debug_jav.html
E.J.
No comments:
Post a Comment