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

    [AJAX]Controllo campo form

    Salve ho provato ha creare un piccolo script con ajax e php per controllare i campi se sono gia in uso ma non capisco perchè non funzionino. Posto il codice da me utilizzato:
    codice:
    var xmlHttp = getXmlHttpObject();
    function loadgif(nome, id){
    xmlHttp.open('GET', 'controlla.php?campo='+campo+'&valore='+id, true);
    xmlHttp.onreadystatechange = stateChanged2();
    xmlHttp.send(null);
    }
    function getvalore(campo) {
    	return campo.value;
    }
    function stateChanged2() {
    	if(xmlHttp.readyState == 4) {
    	//Stato OK
    		if (xmlHttp.status == 200) {
    			var resp = xmlHttp.responseText;
    			if (resp==1){
    				document.write("<img src=\"images/right.gif\" />");
    			}
    			else{
    				alert('nick non valido');
    			}
    				
    		} 
    		else {
    			alert(xmlHttp.responseText);
    		}
    	}
    }
    function getXmlHttpObject()
    {
      var xmlHttp=null;
      try
        {
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
        }
      catch (e)
        {
        // Internet Explorer
        try
          {
          xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
          }
        catch (e)
          {
          xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
        }
      return xmlHttp;
    }function stateChanged2() {
    	if(xmlHttp.readyState == 4) {
    		if (xmlHttp.status == 200) {
    			var resp = xmlHttp.responseText;
    			if (resp==1){
    				document.write("<img src=\"images/right.gif\" />");
    			}
    			else{
    				alert('nick non valido');
    			}
    				
    		} 
    		else {
    			alert(xmlHttp.responseText);
    		}
    	}
    }
    function getXmlHttpObject()
    {
      var xmlHttp=null;
      try
        {
        xmlHttp=new XMLHttpRequest();
        }
      catch (e)
        {
        try
          {
          xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
          }
        catch (e)
          {
          xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
        }
      return xmlHttp;
    }
    Naturalmente lo script php restituisce o 1 o 0. Attraverso onChange richiamo loadgif.

  2. #2
    up

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.