Visualizzazione dei risultati da 1 a 8 su 8

Discussione: ajax.request mootools

  1. #1
    Utente di HTML.it L'avatar di agenti
    Registrato dal
    Feb 2002
    Messaggi
    2,427

    ajax.request mootools

    codice:
    	var ajax = new Ajax('mypage_2.htm', {
    		update: $('update'),
    		onRequest: function() {
    			this.options.update.setHTML("Loading...");
    		},
    		onComplete: function(text) {
    			alert("Complete! " + text);
    		},
    		onFailure: function() {
    			alert("Non è stato possibile eseguire la richiesta correttamente");
    		}
    	});
    
    
    		ajax.request();

    ho trovato questo esempio...
    iol mio dubbio è:

    se volessi passare l'url coem parametro volta per volta...

    dovrei fare così ?

    codice:
    <script>
    	var ajax = new Ajax(url, {
    		update: $('update'),
    		onRequest: function() {
    			this.options.update.setHTML("Loading...");
    		},
    		onComplete: function(text) {
    			alert("Complete! " + text);
    		},
    		onFailure: function() {
    			alert("Non è stato possibile eseguire la richiesta correttamente");
    		}
    	});
    
    
    		ajax.request('mypage_2.htm');
    
    </script>
    <div id="update"></div>



    :master:

  2. #2
    ci sono vari metodi, il più semplice è un Wrapper tipo questo
    codice:
    function WAjax(url){
    	return	new Ajax(url, {
    		update: $('update'),
    		onRequest: function() {
    			this.options.update.setHTML("Loading...");
    		},
    		onComplete: function(text) {
    			alert("Complete! " + text);
    		},
    		onFailure: function() {
    			alert("Non è stato possibile eseguire la richiesta correttamente");
    		}
    	});
    };
    
    WAjax('mypage_2.htm').request();


    [edit]
    per completare, un altor metodo è il self wrapping tramite extended prototype
    codice:
    Ajax = (function(Ajax){
    	function I(){};
    	I.prototype = Ajax.prototype;
    	function MyAjax(url, Object){
    		if(this instanceof MyAjax)
    			Ajax.call(this, url, Object);
    		else
    			return	new MyAjax(url, Object);
    	};
    	MyAjax.prototype = new I;
    	MyAjax.prototype.constructor = Ajax;
    	return	MyAjax;
    })(Ajax);
    
    var	ajax = new Ajax(url, {obj:ect});
    ajax.request();
    // oppure, tramite factory design pattern implicito
    Ajax(url, {obj:ect}).request();
    Io avrei usato questo, ma è un pelino più arduo da comprendere (se interessa, link in sign circa JavaScript prototypal inheritance, c'è questo ed altro ancora)
    Formaldehyde a new Ajax PHP Zero Config Error Debugger

    WebReflection @WebReflection

  3. #3
    Utente di HTML.it L'avatar di agenti
    Registrato dal
    Feb 2002
    Messaggi
    2,427
    qualcosa non mi quadra...


    Ho scaricato la libreria core di mootools...

    ho inserito il tuo script:
    codice:
    <head>
    <script type="text/javascript" src="../js/mootools1.js"></script>
    <script>
    function WAjax(url){
    	return	new Ajax(url, {
    		update: $('update'),
    		onRequest: function() {
    			this.options.update.setHTML("Loading...");
    		},
    		onComplete: function(text) {
    			alert("Complete! " + text);
    		},
    		onFailure: function() {
    			alert("Non è stato possibile eseguire la richiesta correttamente");
    		}
    	});
    };
    
    
    </script>
    </head>
    <body>
    <div id="update"></div>
    
    Test
    
    </body>
    l'errore è:

    Errore: Ajax is not defined
    File sorgente: http://localhost/private/test_scope.asp
    Riga: 5

  4. #4
    Utente di HTML.it L'avatar di dottwatson
    Registrato dal
    Feb 2007
    Messaggi
    3,012
    una soluzione potrebbe essere

    Codice PHP:
    coll_ajax=[];

    $(
    '*').each(function(target,i){

    if (
    target.getProperty('remote') != '')
      {
    coll_ajax[i]=new Ajax(target.getProperty('remote'), {
            
    update: $('update'),
            
    onRequest: function() {
                
    target.options.update.setHTML("Loading...");
            },
            
    onComplete: function(text) {
                
    alert("Complete! " text);
            },
            
    onFailure: function() {
                
    alert("Non è stato possibile eseguire la richiesta correttamente");
            }
        });
      }


    })

    [
    url="#"]link[/url
    Non sempre essere l'ultimo è un male... almeno non devi guardarti le spalle

    il mio profilo su PHPClasses e il mio blog laboweb

  5. #5
    Utente di HTML.it L'avatar di dottwatson
    Registrato dal
    Feb 2007
    Messaggi
    3,012
    cioa.. rileggendola mi sono reso conto che ho commesso un errore ....


    Codice PHP:
    coll_ajax=[];

    $(
    '*').each(function(target,i){

    if (
    target.getProperty('remote') != '')
      {
    coll_ajax[i]=new Ajax(target, {
            
    update: $('update'),
            
    onRequest: function() {
                
    target.options.update.setHTML("Loading...");
            },
            
    onComplete: function(text) {
                
    alert("Complete! " text);
            },
            
    onFailure: function() {
                
    alert("Non è stato possibile eseguire la richiesta correttamente");
            }
        });
      }


    })

    [
    url="#"]link[/url
    Non sempre essere l'ultimo è un male... almeno non devi guardarti le spalle

    il mio profilo su PHPClasses e il mio blog laboweb

  6. #6
    Utente di HTML.it L'avatar di agenti
    Registrato dal
    Feb 2002
    Messaggi
    2,427
    in poche parole con questa funzione riesco a usare i link senza richiamare una funzione su un evento onclick ?

  7. #7
    Utente di HTML.it L'avatar di dottwatson
    Registrato dal
    Feb 2007
    Messaggi
    3,012
    beh, nol mio esempio non c'era l' evento , ma si può fare così

    Codice PHP:
    $('*').each(function(target,i){

      if (
    target.getProperty('remote') != '')
        {
        
    target.addEvent('click',function (){
            var 
    MyReq=new Ajax(target, {
                                        
    update: $('update'),
                                        
    onRequest: function() {
                                            
    target.options.update.setHTML("Loading...");
                                        },
                                        
    onComplete: function(text) {
                                            
    alert("Complete! " text);
                                        },
                                        
    onFailure: function() {
                                            
    alert("Non è stato possibile eseguire la richiesta correttamente");
                                        }
                              });                  
                      });
        }
    });

    [
    url="javascript: void(0)"]link[/url
    Non sempre essere l'ultimo è un male... almeno non devi guardarti le spalle

    il mio profilo su PHPClasses e il mio blog laboweb

  8. #8
    Utente di HTML.it L'avatar di agenti
    Registrato dal
    Feb 2002
    Messaggi
    2,427
    ok lo provo prima possibile..

    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.