473,887 Members | 2,357 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 15088
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
10438
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
2552
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
11895
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
6431
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
3177
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
2086
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
3148
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
3333
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
4617
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
9799
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
10770
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
10875
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
10432
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...
0
9593
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
7141
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
5809
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...
1
4632
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
2
4238
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.