Visualizzazione dei risultati da 1 a 3 su 3

Discussione: jquery & haha

  1. #1

    jquery & haha

    Ho sempre usato Haha inserendolo direttamente nell'evento onclick dei miei link.
    Da poco mi sto avvicinando a jquery e vorrei eliminare dal codice html l'evento onclick e farlo aggiungere direttamente da jquery al caricamento della pagina.

    Il vecchio codice dei link era un qualcosa del genere:
    Codice PHP:
    [url="http://127.0.0.1/pages/My Dropbox/index.php/home"]Home[/url
    ora ho trasformato i link in questo formato:
    Codice PHP:
    [url="http://127.0.0.1/pages/My Dropbox/index.php/home"]Home[/url
    Nell'head della pagina ho inserito:
    codice:
    <script language="javascript" type="text/javascript">
      
    	  $(document).ready(function()
    	  {
    		$("a.hahamenu").click(function(){
    			url = this.id;
    			haha(url, 'haha_div');
    			/*return false;*/ /*ho provato sia con che senza questa riga
    		});
    	});
      </script>
    Ma purtroppo non funziona (se mi limito ad un semplici alert(url); funziona perfettamente).
    Qualcuno ha qualche idea a riguardo?
    ringrazio in anticipo
    saluti
    stefano

    PS: una volta sistemato il fatto di haha che non parte per evitare che venga eseguito anche il link normale invece di usare il return false che penso possa dare problemi non mi conviene usare prima della chiamata ad haha questo:
    codice:
    this.href = '#';

  2. #2
    Per completezza posto anche la funzione ahah

    codice:
    function ahah(url, target, delay, method, parameters) {
    
      if (method == undefined) {
    	  document.getElementById(target).innerHTML = 'caricamento dati in corso...';
    	  if (window.XMLHttpRequest) {
    		req = new XMLHttpRequest();
    	  } else if (window.ActiveXObject) {
    		req = new ActiveXObject("Microsoft.XMLHTTP");
    	  }
    	  if (req) {
    		req.onreadystatechange = function() {
    			ahahDone(url, target, delay, method, parameters);
    		};
    		req.open("GET", url, true);
    		req.send("");
    	  }  
      }
      if ( (method == "GET") || (method == "get") )
      {
    	  document.getElementById(target).innerHTML = 'caricamento dati in corso...';
    	  if (window.XMLHttpRequest) {
    		req = new XMLHttpRequest();
    	  } else if (window.ActiveXObject) {
    		req = new ActiveXObject("Microsoft.XMLHTTP");
    	  }
    	  if (req) {
    		req.onreadystatechange = function() {
    			ahahDone(url, target, delay, method, parameters);
    		};
    		req.open(method, url, true);
    		req.send("");
    	  }
      }
    
      if ( (method == "POST") || (method == "post") )
      {
    	  document.getElementById(target).innerHTML = 'caricamento dati in corso...';
    	  if (window.XMLHttpRequest) {
    		req = new XMLHttpRequest();
    	  } else if (window.ActiveXObject) {
    		req = new ActiveXObject("Microsoft.XMLHTTP");
    	  }
    	  if (req) {
    		req.onreadystatechange = function() {
    			ahahDone(url, target, delay, method, parameters);
    		};
    		req.open(method, url, true);
    		req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    		req.send(parameters);
    	  }
      }
    }  
    
    function ahahDone(url, target, delay, method, parameters) {
      if (req.readyState == 4) {
        if (req.status == 200) {
          document.getElementById(target).innerHTML = req.responseText;
        } else {
          document.getElementById(target).innerHTML="\n"+req.statusText;
        }
      }
    }

  3. #3
    risolto...
    o meglio ho lasciato perdere haha e ho usato la funzione load di jquery.
    Però non capisco perchè debba usare per forza un percorso relativo mentre non posso usare il percorso completo compreso di http://miosito ecc.
    (con haha potevo raggiungere lo script nel modo che preferivo :/)

    codice:
    $(document).ready(function()
    	  {
    		$("a.hahamenu").click(function(){
    			this.href = '#';
    			$("#haha").load('haha/'+this.id);
    		});
    	});
    esempio d link:
    codice:
    	Territorio

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 © 2026 vBulletin Solutions, Inc. All rights reserved.