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

    [AJAX] ottengo il responseXML ma non sono in readyState=4

    Ciao,
    sto facendo uno scrippettino ajax che chiama una pagina che restituisce un xml.
    Il problema che ho e' che il readystate rimane ad 1 non va mai a 4 anche se da Firebug vedo già la response.

    Questo e' il codice:

    codice:
    /*
     * Returns a new XMLHttpRequest object, or false if this browser
     * doesn't support it
     */
    function newXMLHttpRequest() {
    
        var xmlreq = false;
    
        if (window.XMLHttpRequest) {
    
            // Create XMLHttpRequest object in non-Microsoft browsers
            xmlreq = new XMLHttpRequest();
    
        } else if (window.ActiveXObject) {
    
            // Create XMLHttpRequest via MS ActiveX
            try {
                // Try to create XMLHttpRequest in later versions
                // of Internet Explorer
    
                xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
    
            } catch (e1) {
    
                // Failed to create required ActiveXObject
    
                try {
                    // Try version supported by older versions
                    // of Internet Explorer
    
                    xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
    
                } catch (e2) {
    
                    // Unable to create an XMLHttpRequest with ActiveX
                }
            }
        }
    
        return xmlreq;
    }
    
    function doSearch(url) {
        var xmlreq = newXMLHttpRequest();
    
        var defu = url + "?n=" + document.getElementById("n").value;
        alert(defu);
    
        xmlreq.open("GET", defu, true);
    
        xmlreq.onreadystatechange = updateField(xmlreq);
        xmlreq.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
        xmlreq.send(null);
    
    }
    
    function updateField(req) {
        var div = document.getElementById("akappa");
        div.innerHTML="Ecchime...";
        alert(req.readyState);
    
        
        if (req.readyState == 4) {
    
    
            if (req.status == 200) {
                   var out = req.responseXML.getElementsByTagName("wc:INSTANCE");
    
    
                div.innerHTML="Numero elementi: "+out.length;
    
    
    
    
                
            }
        }
    }
    
    
    function test() {
        alert("did");
    }
    Mi sapete aiutare?

    Grazie

  2. #2
    Mi rispondo da solo, il problema e dovuto al fatto che alla funzione di callback passo la xmlreq, mettendola globale funziona tutto.

    Ora mi chiedo non è possibile farlo? Oppure sbagliavo io a farlo?

    grazie

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.