473,473 Members | 2,032 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Firefox XMLHttpRequest onreadystatechange handler not called

Hi,

I thought it is about time I tried writing some JavaScript with
XMLHttpRequest instead of just using the Yahoo! UI library. The simple
page below works in both Safari and Opera but I don't see the alert in
Firefox. Looking in Firefox's firebug plugin, I see that the request is
successfully sent and the correct response is received. Any ideas what
is wrong?

Thank you,
Peter
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Simple XMLHttpRequest</title>

<script type="text/javascript">

function makeRequest(method, url) {
var request = new XMLHttpRequest();

request.onreadystatechange = function() {
if (request.readyState == 4) {
// alert happens in Safari and Opera
// alert doesn't happen in Firefox
alert('handling readyState 4')
}
};

request.open(method, url);
request.send(null);
};

</script>

</head>

<body>

<p id="one">
<a href="#" onclick="makeRequest('GET', '/front/update'); return
false;">
do it!
</a>
</p>

</body>
</html>

Sep 13 '06 #1
2 21855
pe**********@gmail.com wrote:
Hi,

I thought it is about time I tried writing some JavaScript
with XMLHttpRequest instead of just using the Yahoo! UI
library. The simple page below works in both Safari and
Opera but I don't see the alert in Firefox. Looking in
Firefox's firebug plugin, I see that the request is
successfully sent and the correct response is received.
Any ideas what is wrong?
Without reading any more I would guess that the answer is that you are
making a synchronous request.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Simple XMLHttpRequest</title>

<script type="text/javascript">

function makeRequest(method, url) {
var request = new XMLHttpRequest();

request.onreadystatechange = function() {
if (request.readyState == 4) {
// alert happens in Safari and Opera
// alert doesn't happen in Firefox
alert('handling readyState 4')
}
};

request.open(method, url);
<snip>

It may also be an idea to move the assignment of the handler to after
the - open - call as I have a vague recollection of someone's
documentation saying that - open - strips the handler in their xml http
request objects. But you don't have a third argument for - open - and so
undefined may be taken as false, which equates to synchronous requests.
Mozilla does not call the readystate handler for synchronous requests so
you do something like:-

xmlhttp.open(type, URL, asynchronous);
if(asynchronous){
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState == 4){
callbackFnc(xmlhttp);
xmlhttp.onreadystatechange = retFalse;
xmlhttp = null;
}
};
}
xmlhttp.send((data||null));
if(!asynchronous){
callbackFnc(xmlhttp);
xmlhttp = null;
}

Richard.
Sep 13 '06 #2
have to call request.open() first
For example:
request.open(method, file);
pe**********@gmail.com wrote:
Hi,

I thought it is about time I tried writing some JavaScript with
XMLHttpRequest instead of just using the Yahoo! UI library. The simple
page below works in both Safari and Opera but I don't see the alert in
Firefox. Looking in Firefox's firebug plugin, I see that the request is
successfully sent and the correct response is received. Any ideas what
is wrong?

Thank you,
Peter
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Simple XMLHttpRequest</title>

<script type="text/javascript">

function makeRequest(method, url) {
var request = new XMLHttpRequest();

request.onreadystatechange = function() {
if (request.readyState == 4) {
// alert happens in Safari and Opera
// alert doesn't happen in Firefox
alert('handling readyState 4')
}
};

request.open(method, url);
request.send(null);
};

</script>

</head>

<body>

<p id="one">
<a href="#" onclick="makeRequest('GET', '/front/update'); return
false;">
do it!
</a>
</p>

</body>
</html>
Sep 14 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Börni | last post by:
Dear group, i have some experience with javascript, but now i am trying to do object oriented programming with it and i am somehow stuck. I have tried the code so far only in Mozilla 1.7.3 I am...
4
by: Robloche | last post by:
Hi, I wrote a class to handle requests from the client-side. In particular, I use : fuction myClass() { // ... this.xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); // ... }
9
by: David | last post by:
Hello I'm testing the XMLHttpRequest object in Firefox and IE. The code below works well in IE and Firefox. It shows "1" when the string is a number and "0" when not. The page aspxTest.aspx only...
7
by: SE | last post by:
Hi all, Apologies if this has been done before. I am trying to do some stuff with XMLHttpRequest in mozilla but no dice. I have finally pared everything down to the minimum to see what is...
9
by: Eric Wallstedt | last post by:
I have a page that "logs" changes made to input fields using ajax to pass data to a cgi. I use POST and it works fine most of the time (all the time in IE). But it fails when I get the data from...
1
by: weston | last post by:
So, the following apparently works as a method of grafting a method onto an object (using the squarefree JS shell): obj = { x: 1, inc: null } result obj.inc = function () { this.x++ } result...
13
by: TLaufenberg | last post by:
I'm new to Javascript programming and I've run into a bit of a snag with making an XMLHttpRequest in the Safari browser. Actually, the request doesn't work in Firefox either but only when I use a...
5
by: Heofz | last post by:
Hey all, I've been banging my head against a brick wall on this one for the last 12 hours, and the time has come for me to give up and consult the gurus on this one. The below URL contains a...
5
by: Herkum | last post by:
I created this generic AJAX Handler to work with Firefox and IE. However, it seems that somewhere in updating Firefox to 2.0.0.9 that the handler assigned to onreadystatechange is no longer getting...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.