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

    proprietà di un oggetto di un oggetto (standard)

    Non riesco assolutamente a capire perchè non si imposta...a rigor di logica dovrebbe funzionare, ma dice che "obj" has no properties...

    codice:
    function tmp() {
    	this.obj=new XMLHttpRequest();
    	this.cp=function () {
    		if (this.obj.readyState==0) {//Uninitialized
    			//
    		}
    		if (this.obj.readyState==1) {//Loading
    			document.getElementById("mypage").innerHTML="Loading...";
    		}
    		if (this.obj.readyState==2) {//Loaded
    			//
    		}
    		if (this.obj.readyState==3) {//Interactive
    			//
    		}
    		if (this.obj.readyState==4) {//Complete
    			document.getElementById("mypage").innerHTML=this.obj.responseText;
    		}
    	}
    }
    var k=new tmp();
    k.obj.onreadystatechange=k.cp;
    try {
    	k.obj.open("GET","read.xml",true);
    	k.obj.send(null);
    } catch(e) {
    	alert("Problems in loading the page");
    }

  2. #2
    Codice PHP:
    function tmp() {
        
    this.obj=new XMLHttpRequest();
        
    this.cp=function () {
            if (
    this.obj.readyState==0) {//Uninitialized
                //
            
    }
            if (
    this.obj.readyState==1) {//Loading
                
    document.getElementById("mypage").innerHTML="Loading...";
            }
            if (
    this.obj.readyState==2) {//Loaded
                //
            
    }
            if (
    this.obj.readyState==3) {//Interactive
                //
            
    }
            if (
    this.obj.readyState==4) {//Complete
                
    document.getElementById("mypage").innerHTML=this.obj.responseText;
            }
        }
    }

    var 
    k=new tmp();
    k.obj.onreadystatechange=function(){
        
    k.cp();
    }
    try {
        
    k.obj.open("GET","iwdn.php",true);
        
    k.obj.send(null);
    } catch(
    e) {
        
    alert("Problems in loading the page");

    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  3. #3
    Oh...tutto qua?ho testato tipo fino alle 2 di notte e non ho provato solo quello...mi prende a male <.<

    spero NON funzioni sennò rosico XD

    grazie mille cmq

  4. #4
    Ho provato come hai detto te ma non va...poi ho provato così

    Codice PHP:
    function lib_xml_initialize() {
        
    this.obj=null;
        
    this.Loading="Loading...";
        
    this.Writer="mypage";

        try {
            
    // Firefox, Opera 8.0+, Safari
            
    this.obj=new XMLHttpRequest();
        } catch (
    e) {
            
    // Internet Explorer
            
    try {
                
    this.obj=new ActiveXObject("Msxml2.XMLHTTP");
            } catch (
    e) {
                
    this.obj=new ActiveXObject("Microsoft.XMLHTTP");
            }
        }
        
    this.Page=function () {
            if (
    this.obj.readyState==0) {//Uninitialized
                //
            
    }
            if (
    this.obj.readyState==1) {//Loading
                
    document.getElementById(this.Writer).innerHTML=this.Loading;
            }
            if (
    this.obj.readyState==2) {//Loaded
                //
            
    }
            if (
    this.obj.readyState==3) {//Interactive
                //
            
    }
            if (
    this.obj.readyState==4) {//Complete
                
    document.getElementById(this.Writer).innerHTML=this.obj.responseText;
            }
        }

        
    this.AdvancedLoad=function (tipo,surl,async,tosend,user,pass) {
            if (
    this.obj==null) {
                
    alert("Your browser doesn't support XMLHTTP");
                return 
    false;
            }
            try {
                
    this.obj.onreadystatechange=function () {
                    if (
    this.obj.readyState==0) {//Uninitialized
                        //
                    
    }
                    if (
    this.obj.readyState==1) {//Loading
                        
    document.getElementById(this.Writer).innerHTML=this.Loading;
                    }
                    if (
    this.obj.readyState==2) {//Loaded
                        //
                    
    }
                    if (
    this.obj.readyState==3) {//Interactive
                        //
                    
    }
                    if (
    this.obj.readyState==4) {//Complete
                        
    document.getElementById(this.Writer).innerHTML=this.obj.responseText;
                    }
                }
                
    this.obj.open(tipo,surl,async,user,pass);
                
    this.obj.send(tosend);
                return 
    true;
            } catch(
    e) {
                
    alert("Problems in loading the page");
                return 
    false;
            }
            return 
    true;
        }

        
    this.Load=function (tipo,surl,async,tosend) {
            if (
    this.obj==null) {
                
    alert("Your browser doesn't support XMLHTTP");
                return 
    false;
            }
            try {
                
    this.obj.onreadystatechange=function () {
                    if (
    this.obj.readyState==0) {//Uninitialized
                        //
                    
    }
                    if (
    this.obj.readyState==1) {//Loading
                        
    document.getElementById(this.Writer).innerHTML=this.Loading;
                    }
                    if (
    this.obj.readyState==2) {//Loaded
                        //
                    
    }
                    if (
    this.obj.readyState==3) {//Interactive
                        //
                    
    }
                    if (
    this.obj.readyState==4) {//Complete
                        
    document.getElementById(this.Writer).innerHTML=this.obj.responseText;
                    }
                }
                
    this.obj.open(tipo,surl,async);
                
    this.obj.send(tosend);
                return 
    true;
            } catch(
    e) {
                
    alert("Problems in loading the page");
                return 
    false;
            }
            return 
    true;
        }

        
    this.EasyLoad=function (surl) {
            return 
    this.Load("GET",surl,true,null);
        }

    E in un html ho fatto

    codice:
    <html>
    <head>
    <script language="javascript" type="text/javascript" src="lib_xml.js"></script>
    </head>
    <body>
    <input type="button" OnMouseUp="javascript:XmlEasyLoad(k,'read.xml');" value="P1" />
    <input type="button" OnMouseUp="javascript:p2();" value="P2" />
    <input type="button" OnMouseUp="javascript:p3();" value="P3" />
    <div id="mypage">
    Prima di effettuare il cambio pagina
    </div>
    <div id="my2page">
    
    Posto per altre cose
    </div>
    <script language="javascript" type="text/javascript">
    var xmlObj=new lib_xml_initialize();
    xmlObj.EasyLoad("read.xml");
    </script>
    </body>
    </html>
    ma l'errore è sempre lo stesso: this.obj has no properties!

    dio santo...così non ho modo di creare un oggetto che mi faccia da standard...

  5. #5
    Ho fatto un piccolo update al codice javascript...uso questo:

    adesso ci sono quasi...il problema è che si ferma a readyState 0(uninitialized)

    Codice PHP:
    function lib_xml_initialize() {
        
    //Properties
        
    this.obj=null;
        
    this.Loading="Loading...";
        
    this.Writer="mypage";

        
    //Methods
        
    this.Page=function () {
            
    alert("pagina"+this.obj.readyState);
            if (
    this.obj.readyState==0) {//Uninitialized
                //
            
    }
            if (
    this.obj.readyState==1) {//Loading
                
    document.getElementById(this.Writer).innerHTML=this.Loading;
            }
            if (
    this.obj.readyState==2) {//Loaded
                //
            
    }
            if (
    this.obj.readyState==3) {//Interactive
                //
            
    }
            if (
    this.obj.readyState==4) {//Complete
                
    document.getElementById(this.Writer).innerHTML=this.obj.responseText;
            }
        }

        
    this.AdvancedLoad=function (tipo,surl,async,tosend,user,pass) {
            if (
    this.obj==null) {
                
    alert("Your browser doesn't support XMLHTTP");
                return 
    false;
            }
            try {
                
    alert("lol");
                
    this.obj.open(tipo,surl,async,user,pass);
                
    this.obj.send(tosend);
                return 
    true;
            } catch(
    e) {
                
    alert("Problems in loading the page");
                return 
    false;
            }
            return 
    true;
        }

        
    this.Load=function (tipo,surl,async,tosend) {
            if (
    this.obj==null) {
                
    alert("Your browser doesn't support XMLHTTP");
                return 
    false;
            }
            try {
                
    alert("lol");
                
    this.obj.open(tipo,surl,async);
                
    this.obj.send(tosend);
                return 
    true;
            } catch(
    e) {
                
    alert("Problems in loading the page");
                return 
    false;
            }
            return 
    true;
        }

        
    this.EasyLoad=function (surl) {
            return 
    this.Load("GET",surl,true,null);
        }

        try {
            
    // Firefox, Opera 8.0+, Safari
            
    this.obj=new XMLHttpRequest();
        } catch (
    e) {
            
    // Internet Explorer
            
    try {
                
    this.obj=new ActiveXObject("Msxml2.XMLHTTP");
            } catch (
    e) {
                
    this.obj=new ActiveXObject("Microsoft.XMLHTTP");
            }
        }

        
    //Events
        
    this.obj.onreadystatechange=this.Page();


  6. #6
    Scusa ma perchè vuoi complicarti la vita ?

    Tanti giretti per nulla

    Vabè che è a scopo didattico ma.......

    Penso che una cosa del genere possa
    bastare ed è ispirata da alistapart
    con qc di andr3a ed è pure vecchia
    ...........

    Codice PHP:
    function XHConn(){
        var 
    xmlhttp null;
        var 
    resulttrue;
        var 
    browser navigator.userAgent.toUpperCase();
        if(
    typeof(XMLHttpRequest) === "function" || typeof(XMLHttpRequest) === "object"){
                    
    xmlhttp = new XMLHttpRequest();
        }
        else if(
    window.ActiveXObject && browser.indexOf("MSIE 4") < 0){
            if(
    browser.indexOf("MSIE 5") < 0){
                
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
            }
            else{
                
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
        }
        if (
    xmlhttp===null){resultfalse;}
        
    this.connect = function(sURLsMethodsVarsfnDonefnError){
            
    sMethod sMethod.toUpperCase();
            
    xmlhttp.open(sMethodsURLtrue);
            if(
    sMethod == "POST"){
                
    xmlhttp.setRequestHeader("Method""POST "+sURL+" HTTP/1.1");
                
    xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
                
    xmlhttp.setRequestHeader('Content-Length'sVars.length);
            }
            
    xmlhttp.onreadystatechange = function(){
                if (
    xmlhttp.readyState == 4){
                    if(
    xmlhttp.status == 200){
                        
    fnDone(xmlhttp);
                       }
                    else{
                           
    fnError(xmlhttp);
                    }
                }
            }
            
    xmlhttp.setRequestHeader("connection""close");
            
    xmlhttp.send(sVars);
        }
        return 
    result;
    }
    function 
    errorHandler(xhr){
        
    alert("HTTP error: "+xhr.status);


    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  7. #7
    Per il semplice fatto che in questo modo posso avere un solo oggetto XmlHTTPRequest
    per volta...e se volessi caricare due pagine in contemporanea, la cosa non si può fare (ammenochè non ne faccio caricare una per volta, ovviamente)

    allora ho creato quell'oggetto che dovrebbe semplificarne la creazione, ma a quanto pare...non è affatto così-.-

    maledetta libreria...

    in teoria dovrebbe funzionare in quel modo...infatti non dà errori, ma ora resta fermo su readyState 0...ma pure status è a 0...neanche a dire che mi dicesse pagina non trovata...

  8. #8
    con gli array funziona..userò quelli anche se non mi piace...

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.