473,686 Members | 2,788 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[XMLHttpRequest] - onreadystatecha nge work in IE nothin in mozilla

hello,

I'm writing a program using XMLHttpRequest that works in the main case
on IE and mozilla but this code works only on IE ... why ?

probleme is located at mark 'HERE' at the end of code.

{__start_of_cod e__} ('piece' of code)

....
// OBJ. HTTP
function getHTTPObject() {
var xmlhttp;
/*@cc_on
@if (@_jscript_vers ion >= 5)
try {
xmlhttp = new ActiveXObject(" Msxml2.XMLHTTP" );
} catch (e) {
try {
xmlhttp = new ActiveXObject(" Microsoft.XMLHT TP");
} catch (E) {
xmlhttp = false;
}
}
@else
xmlhttp = false;
@end @*/
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
try {
xmlhttp = new XMLHttpRequest( );
} catch (e) {
xmlhttp = false;
}
}
return xmlhttp;
}

<!-- OBJETS HTTP -->
var http = getHTTPObject() ;
var http1 = getHTTPObject() ;
var http2 = getHTTPObject() ;

// GESTION EVENT AJAX
function handleHttpRespo nse(varhttp,con text){
switch (varhttp.readyS tate){
case 4:
switch (context){
case 'search':
...
break ;
case 'addline':
var sbar = document.getEle mentById("sbar" ) ;
sbar.innerHTML += varhttp.respons eText ;
pbar1.next() ;
break ;
case 'ping':
...
break ;
default:
alert("!! ERROR !!") ;
break ;
}
break ;
case 3:
logger("Status : Transfert de donnees en cours...") ;
break ;
case 2:
logger("Status : Attente de la reponse...") ;
break ;
case 1:
logger("Status : Connexion au serveur...") ;
break ;
case 0:
logger("Status : Connexion non initialise !! ") ;
break ;
}
}
function wake(cnt){

var url_base =
document.getEle mentById("machi nelist").getEle mentsByTagName( "a")[cnt] ;
var url_sbar = new String(url_base ) ;

if (url_base) {

url_sbar = url_sbar.replac e("index.php"," proc.php");
url_sbar = url_sbar.replac e("wakeup","aja xbehav_sbar");

// JS SYNCHRONE !!
http1.open("GET ", url_sbar,false) ;
// HERE !!!!!
// this line has no effect ; state never change !!!
http1.onreadyst atechange=funct ion(){handleHtt pResponse(http1 ,"addline")}
;
///////////////////////////////////////////////
http1.send(null ) ;

http2.open("GET ", url_base,false) ;
http2.send(null ) ;
//=============== =============== ======

}

}
....
{__end__}

how this code return no error in any browser but works only on IE ??

thanks.

regards.

Aug 29 '06 #1
2 6192


jh****@gmail.co m wrote:

// JS SYNCHRONE !!
http1.open("GET ", url_sbar,false) ;
// HERE !!!!!
// this line has no effect ; state never change !!!
http1.onreadyst atechange=funct ion(){handleHtt pResponse(http1 ,"addline")}
;
///////////////////////////////////////////////
http1.send(null ) ;
If you make a synchronous request then the send() call blocks your
script until the response is there and you don't need an
onreadystatecha nge event handler but you should simply have your code
check the status, responseText and so on directly here after the send
call. Firefox does not fire onreadystatecha nge for the synchronous call.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 29 '06 #2

it's OK ;) - that works

thanks...

Martin Honnen wrote:
jh****@gmail.co m wrote:

// JS SYNCHRONE !!
http1.open("GET ", url_sbar,false) ;
// HERE !!!!!
// this line has no effect ; state never change !!!
http1.onreadyst atechange=funct ion(){handleHtt pResponse(http1 ,"addline")}
;
///////////////////////////////////////////////
http1.send(null ) ;

If you make a synchronous request then the send() call blocks your
script until the response is there and you don't need an
onreadystatecha nge event handler but you should simply have your code
check the status, responseText and so on directly here after the send
call. Firefox does not fire onreadystatecha nge for the synchronous call.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 30 '06 #3

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

Similar topics

5
10269
by: Jarson | last post by:
My JavaScript is trying to POST data to a CGI script (Perl) using XMLHttpRequest. My CGI server gets different data from IE than Mozilla Firefox. // For Mozilla, req = new XMLHttpRequest(); // For IE req = new ActiveXObject("Microsoft.XMLHTTP"); req.onreadystatechange = requestHandler ; // function to handle async response req.open('POST', myURL, true); // use POST req.send('foo=11&bar=22') ;
12
3442
by: knocte | last post by:
Hello. I have always thought that the eval() function was very flexible and useful. If I use it, I can define functions at runtime!! However, I have found a case where eval() does not work properly. It works, for example, when invoking functions (alert('hello')), but not for defining functions. The case occurs when retrieving the javascript code with
7
1886
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();
6
7286
by: Nathan | last post by:
Can I run two XMLHTTPRequest objects at the same time? Im able to get one to work without problems. If I put a call to a function inside the first ones onreadystatechange function, the 2nd ones readyState is always set to 1 (loading). Ive tried using the same XMLHTTPRequest object, and making a 2nd XMLHTTPRequest object with the same results. Heres my code thats giving me problems... function RefreshChat() {
3
8173
by: keith.schincke | last post by:
I know I must be missing something basic. I am developing of Firefox 1.5 and am trying to to send a basic QUERY_STRING to a test CGI that will print the data back to the brower: I can print my query string with an alert() right before the request.send(queryString). An examination of the cgi enviroment and tcpdump does not show QUERY_STRING being set. Is there some I uncrossed or T on dotted?
2
21869
by: petermichaux | last post by:
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,
13
11488
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...
1
4028
by: geevaa | last post by:
http://www.phpbuilder.com/columns/kassemi20050606.php3 XMLHttpRequest and AJAX for PHP programmers James Kassemi Introduction: Although the concept isn't entirely new, XMLHttpRequest technology is implemented on more sites now than ever. Compatibility is no longer an issue (IE, Mozilla and Opera all support it), and the benefits to using it are amazing. There are too many PHP programmers avoiding any
0
8584
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
8516
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
8932
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
8768
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
8778
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
7599
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...
1
6440
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...
1
2945
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
3
1934
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.