Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    Problema con XMLHTTP ed IE - O.K. su Firefox

    Salve a tutti, sono Daniele,
    e ho un problema con IE, nuova dirà qualcuno, ma è così:

    Per realizzare la chat che sto sviluppando, faccio leggere a XMLHTTP una pagina ogni 4 secondi, e mentre tutto funziona su Firefox, con IE, la pagina richiamata da XMLHTTP, la primna volta viene letta ed eseguita correttamente, mentre le successive, è come se venisse presa dalla cache, viene letta, ma non aggiornata!!! Perchèèèèè...

    E' tutta la giornata che tento di capirci qualcosa, ma niente Vi prego aiutatemi sono disperato!


    Il codice è quello classico, ve lo metto qui sotto:

    codice:
    function loadXMLDoc(url) {
        // branch for native XMLHttpRequest object
        if (window.XMLHttpRequest) {
            req = new XMLHttpRequest();
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send(null);
        // branch for IE/Windows ActiveX version
        } else if (window.ActiveXObject) {
            isIE = true;
            req = new ActiveXObject("Microsoft.XMLHTTP");
            if (req) {
                req.onreadystatechange = processReqChange;
                req.open("GET", url, true);
                req.send();
            }
        }
    }
    
    // handle onreadystatechange event of req object
    function processReqChange() {
        // only if req shows "loaded"
        if (req.readyState == 4) {
            // only if "OK"
            if (req.status == 200) {
    
             QUI RECUPERO LA RISPOSTA E LA VISUALIZZO
    
             setTimeout("loadXMLDoc('test_2.asp')",4000);
    
             } else {
                alert("There was a problem retrieving the XML data:\n" +
                    req.statusText);
             }
        }
    }
    e test_2.asp è semplicemente questa qui:

    codice:
    Questo documento che si chiama test_2.asp E' stato caricato alle <%=time()%>   - Daniele -
    E su Firefox funziona benissimo... dov'è l'errore???


  2. #2

    Re: Problema con XMLHTTP ed IE - O.K. su Firefox

    fai in modo che la url cambi tutte le volte, così eviti che il browser carichi la pagina dalla cache:

    codice:
    function loadXMLDoc(url) {
        // branch for native XMLHttpRequest object
        var t=new Date().getTime();
        url=url+"?t="+t;
        if (window.XMLHttpRequest) {
            req = new XMLHttpRequest();
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send(null);
        // branch for IE/Windows ActiveX version
        } else if (window.ActiveXObject) {
            isIE = true;
            req = new ActiveXObject("Microsoft.XMLHTTP");
            if (req) {
                req.onreadystatechange = processReqChange;
                req.open("GET", url, true);
                req.send();
            }
        }
    }

  3. #3
    Cmq dovevi postare nel forum Javascript

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.