473,795 Members | 3,063 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Firefox XMLHttpRequest onreadystatecha nge 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(met hod, url) {
var request = new XMLHttpRequest( );

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

request.open(me thod, url);
request.send(nu ll);
};

</script>

</head>

<body>

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

</body>
</html>

Sep 13 '06 #1
2 21876
pe**********@gm ail.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(met hod, url) {
var request = new XMLHttpRequest( );

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

request.open(me thod, 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(ty pe, URL, asynchronous);
if(asynchronous ){
xmlhttp.onready statechange = function(){
if(xmlhttp.read yState == 4){
callbackFnc(xml http);
xmlhttp.onready statechange = retFalse;
xmlhttp = null;
}
};
}
xmlhttp.send((d ata||null));
if(!asynchronou s){
callbackFnc(xml http);
xmlhttp = null;
}

Richard.
Sep 13 '06 #2
have to call request.open() first
For example:
request.open(me thod, file);
pe**********@gm ail.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(met hod, url) {
var request = new XMLHttpRequest( );

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

request.open(me thod, url);
request.send(nu ll);
};

</script>

</head>

<body>

<p id="one">
<a href="#" onclick="makeRe quest('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
1835
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 trying to make an object which offers the functionaltity of the xmlhttpRequest object ( my object is something like a wrapper ). the constructor makes an new XMHttpequest object, and then there are methods to POST or GET data. The problem: I...
4
2281
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
17997
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 write "0" or "1" with a "response.write" method. The problem that I have is when I try this example with Synchronous mode. If I change the function sendNum with: xmlhttp.open("GET",url,false);
7
1892
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 happening with this script ----------------------------------------------------- xmlhttp = new XMLHttpRequest();
9
15085
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 a popup that invokes a function that in turn invokes ajax. Scenerio 1. user clicks a button to create a popup 2. the user selects a select member and clicks a button and a
1
2266
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 function () { this.x++; } obj.inc() obj.x result 2
13
11506
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 Mac computer. IE and FireFox on a Windows based system works just fine. The problem I am having is that the XMLHttpRequest doesn't open the site that I've programmed into it. When I check the readyState it only returns 0 and never goes through the...
5
6424
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 login page, you can test it using the details User: marco Pass: polo This seems to work PERFECTLY in opera, and it works in firefox but ONLY if I have firebug enabled. I don't care about IE for now, I'll sort that out later.
5
2150
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 called. This still works for IE. Can someone help me add to this so that I can get it working with Firefox again? var ASYNCH = true; var REQUEST_TYPE = 'POST'; var AJAX_URL = '/ajax.cgi'; function httpRequest() {
0
9672
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10213
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10163
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9040
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6780
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
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 we have to send another system

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.