473,698 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

AJAX problem with firefox (no readyState == 3 ????)

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
function in the calling page is invoked.

3. the ajax function is invoked and the data is passed to the cgi.

if it works I get:

request sent to server... 1... 2... 3... 4... 2006-02-17
13:28:47.491131 |id:2097|name:d ept|seq:0|value :53

when it fails I get:
request sent to server... 1... 2... 4...

where the 1... 2... 3... 4.... are the readyStates

Any ideas?

function rt_AJAX(req) {
document.getEle mentById("messa ge").value = " request sent to
server... ";
xmlhttpPost(req );
}

function xmlhttpPost(req ) {

var xmlHttpReq = false;

req.s1=true;
req.s2=true;
req.s3=true;
req.s4=true;

// IE
if (window.ActiveX Object) {
var xmlHttpReq = new ActiveXObject(" Microsoft.XMLHT TP");
}
// Mozilla/Safari
else {
var xmlHttpReq = new XMLHttpRequest( );
xmlHttpReq.over rideMimeType('t ext/xml');
}

xmlHttpReq.open ('POST', req.url, true);

xmlHttpReq.setR equestHeader('C ontent-Type',
'application/x-www-form-urlencoded');

xmlHttpReq.onre adystatechange = function() {
if (xmlHttpReq.rea dyState == 1) { req.s1=false; }
if (xmlHttpReq.rea dyState == 2) { req.s2=false; }
if (xmlHttpReq.rea dyState == 3) { req.s3=false; }
if (xmlHttpReq.rea dyState == 4) { req.s4=false; }
document.getEle mentById("messa ge").value += xmlHttpReq.read yState
+ "... ";
if (xmlHttpReq.rea dyState == 4) {
try {
req.str=xmlHttp Req.responseTex t;
}
catch(e) {
req.str=e;
}
updatepage(req) ;
if (req.s1 || req.s2 || req.s3 || req.s4) {
alert('Update Failed on the Server ("'+req.name+'" )
Discontinue Use and Contact XXXXXXXXX');
}
}
}

xmlHttpReq.send (getquerystring (req));

}

*** Sent via Developersdex http://www.developersdex.com ***
Feb 17 '06 #1
9 15075
Eric Wallstedt wrote:
if it works I get:

request sent to server... 1... 2... 3... 4... 2006-02-17
13:28:47.491131 |id:2097|name:d ept|seq:0|value :53

when it fails I get:
"It fails" is a broad subject.
request sent to server... 1... 2... 4...

where the 1... 2... 3... 4.... are the readyStates

Any ideas?


<URL:http://msdn.microsoft. com/library/en-us/xmlsdk/html/0e6a34e4-f90c-489d-acff-cb44242fafc6.as p>
<URL:http://msdn.microsoft. com/library/en-us/xmlsdk/html/f6de15fc-72e9-418e-b275-d94b0b2045de.as p>

(yes, I have observed that this is about Firefox)
HTH

PointedEars
Feb 17 '06 #2
VK

Eric Wallstedt wrote:
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
function in the calling page is invoked.

3. the ajax function is invoked and the data is passed to the cgi.

if it works I get:

request sent to server... 1... 2... 3... 4... 2006-02-17
13:28:47.491131 |id:2097|name:d ept|seq:0|value :53

when it fails I get:
request sent to server... 1... 2... 4...

where the 1... 2... 3... 4.... are the readyStates

Any ideas?


Numeric values of readyState are really IE's "table of states" index
values:

[1] : "loading" Object is loading its data.
[2] : "loaded" Object has finished loading its data.
[3] : "interactiv e" User can interact with the object even though it is
not fully loaded.
[4] : "complete" Object is completely initialized

So on error Firefox skips on "interactiv e" and it goes right to
"complete". We may discuss the sense of "complete" in application to a
failed request :-), but it's not a Firefox problem. Microsoft did not
think as of necessary (or just did not think at all) to add the 5th
state like:
[5] : "failed"
and everyone else adopted it as it was, so now we have to check the
status on readyState==4.

I missed though what is your particular disconvenience of it?

Feb 17 '06 #3
Do you know of any workarounds?

Feb 20 '06 #4
Eric W wrote:
Do you know of any workarounds?


Are you referring to something?

<URL:http://jibbering.com/faq/faq_notes/pots1.html#ps1P ost>
<URL:http://www.safalra.com/special/googlegroupsrep ly/>

Anyway, for a workaround to a problem there has to be a problem first.
PointedEars
Feb 20 '06 #5

Do you know how I can trap the error in Firefox? I don't get an error
logged in the javascript console or a status back to check.
*** Sent via Developersdex http://www.developersdex.com ***
Feb 22 '06 #6
Eric W wrote:
Do you know how I can trap the error in Firefox?
Will you understand that there is no error at all?
I don't get an error logged in the javascript console
And that it is not something to be expected, provided your
code is syntactically correct.
or a status back to check.
Then either your server, your user agent or your code is borken.
Most certainly your server and your code are:

| req.s1=true;
| req.s2=true;
| req.s3=true;
| req.s4=true;
| // ...
| xmlHttpReq.onre adystatechange = function() {
| if (xmlHttpReq.rea dyState == 1) { req.s1=false; }
| if (xmlHttpReq.rea dyState == 2) { req.s2=false; }
| if (xmlHttpReq.rea dyState == 3) { req.s3=false; }
| if (xmlHttpReq.rea dyState == 4) { req.s4=false; }
| // ...
| if (xmlHttpReq.rea dyState == 4) {
| // ...
| if (req.s1 || req.s2 || req.s3 || req.s4) {

This evaluates to `true' if readyState == 3 ("User can interact with the
object even though it is not fully loaded.") did _not_ happen (because
req.sq3 is still `true' then). There is no reason why readyState == 3
former must happen, so

| alert('Update Failed on the Server ("'+req.name+'" )
| Discontinue Use and Contact XXXXXXXXX');

is simply a wrong conclusion, especially given that readyState == 4
("'complete' : Object is completely initialized") was already reached.

It only is missing logic in your source code that makes it seem _as if_
there was an error.

| }
| // ...
| }
*** Sent via Developersdex http://www.developersdex.com ***


Don't. Use Google Groups if you have to, use a newsreader if you can.
PointedEars
Feb 22 '06 #7
> if (xmlHttpReq.rea dyState == 4) {
}

As VK pointed:

[1] : "loading" Object is loading its data.
[2] : "loaded" Object has finished loading its data.
[3] : "interactiv e" User can interact with the object even though it is
not fully loaded.
[4] : "complete" Object is completely initialized
readyState==4 does not say that there is an error or not, just that the
request is completed (with or without an error).
After (in) readyState==4, you should check for xmlHttpReq.stat us

Something like this:
if (xmlHttpReq.rea dyState == 4) {

if (xmlHttpReq.sta tus == 200) {
// ok
} else {
// error
}

}
also, check this:
http://msdn.microsoft.com/library/de...4b0b2045de.asp
to see the list of xmlHttpReq.stat us codes

telmo

Feb 22 '06 #8
VK

Eric W wrote:
Do you know how I can trap the error in Firefox? I don't get an error
logged in the javascript console or a status back to check.


If by "error" you mean data retrieval error from the server then:

IXMLHTTPRequest (IE) / XMLHttpRequest (others) has five readyStates
reported by onreadystatecha nge handler:

[0] : "uninitiali zed" : // I missed that one in the first post
[1] : "loading" Object is loading its data.
[2] : "loaded" Object has finished loading its data.
[3] : "interactiv e" User can interact with the object even though it is
not fully loaded.
[4] : "complete" Object is completely initialized

This is by the original IE's notation, but the exact sense of each
state has been adjusted rather creatively :-) in wannabes'
implementations .

In the particular readyState==4 on the majority of implementations
simply means "The ajaxoid stopped any attempts to send/get data to/from
server for this particular transaction."

(readyState==4) says *absolutely nothing* wether it was a successfull
transaction or a failure.

Also as per
<http://msdn.microsoft. com/workshop/author/dhtml/reference/properties/readyState_1.as p>

(wich is currently the only one official documentation for readyState -
not counting wiki'ed revelations):-
<q>The states through which an object passes are determined by that
object; an object can skip certain states (for example, interactive) if
the state does not apply to that object.</q>

Therefore the corrrect and only one available algorithm is to monitor
readyState==4 and check status property to determine if you are lucky
or not.

** No program execution logic can be connected with other readyState's
**

if (xhr.readyState == 4) {
if ((xhr.status == 200)||(xhr.stat us == 0)) {
// you are lucky :-)
}
else {
// you are not
// study .status to know why
}
}

(xhr.status == 0) is needed only if debugging your ajaxoid locally
(file://) or if you want to use it both for server and local files:
because IE returns status 0 for local files.

There is also a known issue with Firefox: in case of server connection
failure (thus not 404 but something really yaky like timeout, unknown,
refused etc) ajaxoid gets unstable. It still calls onreadystatecha nge
handler but on first attempt to read any of his properties it throws an
error and stops the script execution.
Therefore you need to place the state/status check into try-catch
block. It will naturally lead to a syntax error on the older (really
old actually) systems:- but here is the exact situation "damned if you
do, damned if you don't". I would definitely vote for the modern
systems support - but the final choice is up to you. If you decide to
make your program robust for JavaScript 1.5 / JScript 5 and higher (all
systems over the last 6 years) then:

try {
// here you would get an error on Firefox if
// the connection failed
if (xhr.readyState == 4) {
if ((xhr.status == 200)||(xhr.stat us == 0)) {
// you are lucky :-)
}
else {
// you are not
/ / study .status to know why
}
}
}
catch(e) {
// some serious connection error
// you have only guess about
}

And the last but not least: XMLHttpRequest wants send(null) for GET,
IXMLHTTPRequest wants send("") for GET. Otherwise you may get some
funny behavior in some funny situations. So somewhere in the init
block:

/*@cc_on @*/
/*@if (@_jscript)
var dummy = '';
@else @*/
var dummy = null;
/*@end @*/

so later:

xhr.send(dummy) ;

Feb 23 '06 #9
It turns out that there is a bug in firefox regarding ajax and popup
windows....

Bugzilla Bug 317600
nsIXMLHttpReque st throws exception on access of status member when the
request originate from a popup windows

The workaround is have the parent window originate the request!

Thanks everyone for your input!

Feb 23 '06 #10

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

Similar topics

3
10426
by: lodge.stuart | last post by:
Hi I've written a small AJAX-style UI - although it's not strictly AJAX as it uses HTML fragments rather than XML This UI works fine for me and the majority of users. However, a few users are finding it doesn't work at all. I've talked with these users and debugged it a little by adding some
6
2535
by: Nico VanHaaster | last post by:
Hello all, I have run across an issue with IE 6.0+. I have a page that makes an XMLHttpRequest to the webserver to update a report on the page. The first time you hit the refresh report button the data is refreshed, however if you try to refresh the report the onreadystatechage does not seem to fire. I have tested this by placing an alert in the verifyID2 & verifyID3 function to track where the XMLHttpRequest currently is. Now when...
17
11873
by: Arjen | last post by:
Hi, I want to reload 2 divs at one click. Ive tried: <a href = "javascript:void(0);" onclick="show('ajaxrequest.php?action=removefield','div1');show('ajaxrequest.php?action=reloaddiv2','div2')">verwijderen</a> While both seperate actions work they dont when I put them together. Anyone know how to fix this ? My ajax.js with funcition show
5
6414
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.
2
3164
by: shivendravikramsingh | last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if i change something in php file using in ajax function.it not refreshed,means its shows the previous result it not get updated.i can't understand whats the prob.this is the code i m using: <? include("config.inc.php"); //error_reporting(0); ...
1
2076
by: wpt394 | last post by:
I am running a code that works just fine in Firefox, but seems to have trouble in IE. The basic idea is that a travel search process is initiated with one ajax call, and a 2nd ajax call 'updates' the page with the results that have been retrieved thus far. This 2nd call loops until the first call (the search) is complete. Everything works fine in Firefox, but in IE, the 2nd call doesn't work until the very end when the 1st call is complete....
8
3137
by: cyqotiq | last post by:
First, let me state that this is not necessarily a Firefox problem, as I haven't fully tested in IE just yet. Second, let me state that this is not the typical "getElementById not working Firefox" post. Third, there are pieces of this code that I am not at liberty to display, change, discuss, or re-implement. As far as this question is concerned, this means that (1) I cannot use 3rd party libraries, which is why I've implemented my own...
29
3308
by: zalek | last post by:
I am writing application with Ajax in sync mode - xmlHttp.open("GET", url, false). I noticed that in FireFox handler doesn't starts. It starts when I use xmlHttp.open("GET", url,true). I need to use it in sync mode. Any ideas what can I do? Thanks, Zalek.
1
4603
by: javediq143 | last post by:
Hi All, This is my first post in this forum. I'm developing a CMS for my latest website. This CMS is also in PhP & MySQL. I'm done with the ADD section where the Admin can INSERT new records in Database but I'm stuck in the EDIT. I'm getting 2 problems over here. Below is the description: 1)The FIRST page will list all the records from the table which Admin can EDIT with CHECKBOX for each record to select. He can select one or more than one...
0
8673
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
9156
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9021
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
8892
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
8860
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4614
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2327
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1998
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.