[XMLHttpRequest] - onreadystatechange work in IE nothin in mozilla

Discussion in 'Javascript' started by jhullu@gmail.com, Aug 29, 2006.

  1. Guest

    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_code__} ('piece' of code)

    ....
    // OBJ. HTTP
    function getHTTPObject() {
    var xmlhttp;
    /*@cc_on
    @if (@_jscript_version >= 5)
    try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
    try {
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } 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 handleHttpResponse(varhttp,context){
    switch (varhttp.readyState){
    case 4:
    switch (context){
    case 'search':
    ...
    break ;
    case 'addline':
    var sbar = document.getElementById("sbar") ;
    sbar.innerHTML += varhttp.responseText ;
    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.getElementById("machinelist").getElementsByTagName("a")[cnt] ;
    var url_sbar = new String(url_base) ;

    if (url_base) {

    url_sbar = url_sbar.replace("index.php","proc.php");
    url_sbar = url_sbar.replace("wakeup","ajaxbehav_sbar");

    // JS SYNCHRONE !!
    http1.open("GET", url_sbar,false) ;


    // HERE !!!!!
    // this line has no effect ; state never change !!!
    http1.onreadystatechange=function(){handleHttpResponse(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, 2006
    #1
    1. Advertising

  2. wrote:


    > // JS SYNCHRONE !!
    > http1.open("GET", url_sbar,false) ;
    >
    >
    > // HERE !!!!!
    > // this line has no effect ; state never change !!!
    > http1.onreadystatechange=function(){handleHttpResponse(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
    onreadystatechange 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 onreadystatechange for the synchronous call.



    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Aug 29, 2006
    #2
    1. Advertising

  3. Guest

    Re: - onreadystatechange work in IE nothin in mozilla

    it's OK ;) - that works

    thanks...

    Martin Honnen wrote:
    > wrote:
    >
    >
    > > // JS SYNCHRONE !!
    > > http1.open("GET", url_sbar,false) ;
    > >
    > >
    > > // HERE !!!!!
    > > // this line has no effect ; state never change !!!
    > > http1.onreadystatechange=function(){handleHttpResponse(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
    > onreadystatechange 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 onreadystatechange for the synchronous call.
    >
    >
    >
    > --
    >
    > Martin Honnen
    > http://JavaScript.FAQTs.com/
    , Aug 30, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    187
    Benjamin
    Sep 14, 2006
  2. weston
    Replies:
    1
    Views:
    238
    Richard Cornford
    Sep 22, 2006
  3. Peter Michaux
    Replies:
    2
    Views:
    165
    Peter Michaux
    Oct 28, 2006
  4. Replies:
    4
    Views:
    468
  5. HugeBob
    Replies:
    10
    Views:
    267
    HugeBob
    Apr 6, 2007
Loading...

Share This Page