Re: Using XMLHttpRequest in Firefox
- From: "Trevor L." <Trevor L.@Canberra>
- Date: Sun, 22 Jan 2006 15:12:36 +1100
Martin Honnen wrote:
> Trevor L. wrote:
>
>> I pulled the example below from w3schools and made a few cosmetic
>> changes
>
>> if (window.XMLHttpRequest) // NOTE: THIS PATH DOES NOT WORK IN
>> FIREFOX { alert('XMLHttpRequest')
>> xmlhttp = new XMLHttpRequest()
>> if (document.onreadystatechange)
>> xmlhttp.onreadystatechange = state_Change
>> else
>> alert ('document.onreadystatechange not found') // NOTE:
>> THIS ALERT DISPLAYS IN FIREFOX
>
> I don't know the original script but if that if/else is one of your
> "cosmetical changes" then throw it out, it is crap, you need to set
> onreadystatechange on the request object whether that is MSXML or
> Mozilla or any other implementation and you want to do asynchronous
> requests. And document.onreadystatechange does not matter in any way
> for XMLHttpRequest.
>
> See
> <http://www.faqts.com/knowledge_base/view.phtml/aid/6826/fid/616>
> for code that works and has much less code forks, creation of the
> request object is all that is different.
Here is the code from W3schools
http://www.w3schools.com/xml/tryit.asp?filename=try_xmlhttprequest_js
Below is my altered code. The only difference of any consequence is the xml
name in the onload=""
It works in IE6, not in Firefox1.5
<html>
<head>
<script type="text/javascript">
var xmlhttp
//------------------------------
function loadXMLDoc(url)
{
// code for Mozilla, etc.
if (window.XMLHttpRequest)
xmlhttp = new XMLHttpRequest()
// code for IE
else if (window.ActiveXObject)
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
if (xmlhttp)
{ xmlhttp.onreadystatechange = processXML
xmlhttp.open("GET",url,true)
xmlhttp.send(null) }
}
//------------------------------
function processXML()
{
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
alert("XML data OK")
document.getElementById('A1').innerHTML=xmlhttp.status
document.getElementById('A2').innerHTML=xmlhttp.statusText
document.getElementById('A3').innerHTML=xmlhttp.responseText
}
else
alert("Problem retrieving XML data:" + xmlhttp.statusText)
}
//------------------------------
</script>
</head>
<body
onload="loadXMLDoc('http://abc.net.au/news/syndicate/topstoriesrss.xml')">
<h2>Using the HttpRequest Object</h2>
<p><b>status:</b>
<span id="A1"></span>
</p>
<p><b>status text:</b>
<span id="A2"></span>
</p>
<p><b>response:</b>
<br><span id="A3"></span>
</p>
</body>
</html>
The code from your reference tries to open define the xml with:
if (typeof XMLHttpRequest != 'undefined') {
httpRequest = new XMLHttpRequest();
}
This is identical to that in the w3schools example, so why doesn't it work
in Firefox ?
I am still of the opinion that onreadystate is not recognised by Firefox as
evidenced by my alert.
BTW, I note that just as Firefox doesn't recognise ActiveXObject, IE6 also
doesn't recognise XMLHttpRequest.
I note that you are an MVP-XML.
Since I can't get the example at
<http://www.faqts.com/knowledge_base/view.phtml/aid/6826/fid/616> to work,
could I ask you to write a simple piece of code that opens some xml (say
http://abc.net.au/news/syndicate/topstoriesrss.xml) using Firefox and then
post it back here ?
It is beyond me and I have looked carefully at www.w3schools.com and
www.faqts.com as well as
http://www.webreference.com/programming/javascript/jf/column12/index.html
and
http://www.webreference.com/programming/javascript/jf/column13/index.html
--
Cheers,
Trevor L.
Website: http://tandcl.homemail.com.au
.
- Follow-Ups:
- Re: Using XMLHttpRequest in Firefox
- From: Martin Honnen
- Re: Using XMLHttpRequest in Firefox
- References:
- Using XMLHttpRequest in Firefox
- From: Trevor L.
- Re: Using XMLHttpRequest in Firefox
- From: Martin Honnen
- Using XMLHttpRequest in Firefox
- Prev by Date: Re: Using XMLHttpRequest in Firefox
- Next by Date: Re: Best Way to access Input fields
- Previous by thread: Re: Using XMLHttpRequest in Firefox
- Next by thread: Re: Using XMLHttpRequest in Firefox
- Index(es):
Relevant Pages
|