Re: Using XMLHttpRequest in Firefox



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


.



Relevant Pages

  • Re: XMLHttpRequest on page load doesnt work sometimes.
    ... XMLHttpRequest, it then makes a call to open and send and sets the ... When I test it in IE or Firefox the first time the page ... req = new XMLHttpRequest; ... // Use Microsoft event registering method. ...
    (comp.lang.javascript)
  • Firefox + XMLHttpRequest + Anfrage an anderen Server...
    ... wie ich per XMLHttpRequest eine Anfrage an ... open- bekomme aber dann im Firefox die Fehlermeldung ... Ich bekomme auch die Bestätigung aber open() bricht trotzdem mit der ...
    (de.comp.lang.javascript)
  • Getting Ajax to work
    ... a> I am trying to implement some AJAX. ... an XMLHttpRequest and displayed at the top of the page. ... I move the files to internet it doesn't work at all with Firefox. ...
    (comp.lang.javascript)
  • Loading a file on the server - timing issues?
    ... I am loading a text file to a variable with XMLHttpRequest() ... There seems to be some sort of timing issue since loadXML (source code below) ... If I look at the code with Firefox debugger everything works fine. ...
    (comp.lang.javascript)