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

    passaggio di variabile + ajax

    giorno a tutti io ho questo problema

    vorrei passare una variabile (id) dalla funzione controllo alla funzione myHandler... io ho provato facendo codice in rosso... il problema è che la variabile id me la passa, ma poinon mi fa il resto della funzione myHandler... come posso fare?

    function myHandler(id) {
    if (myRequest.readyState == 4 && myRequest.status == 200) {
    var e = document.getElementById(lastid + "last");
    e.innerHTML = myRequest.responseText;
    e.style.color= "red";
    e.style.background= "#FFFF00";
    }

    }

    function controllo(id) {
    var e = document.getElementById(id);
    myRequest = CreateXmlHttpReq(myHandler(id));
    myRequest.open("GET","registrato.php?controllo=" + e.value + "&campo=" + id );
    myRequest.send(null);
    lastid= id;
    }

    grazie

  2. #2
    Frontend samurai L'avatar di fcaldera
    Registrato dal
    Feb 2003
    Messaggi
    12,924
    CreateXmlHttpReq(myHandler(id));


    significa che esegui la funzione myhandler con parametro 'id' e ne assegni il valore di ritorno alla funzione CreateXmlHttpReq.

    Ma la funzione myhandler non ritorna nessun valore, quindi la funzione successiva ha un parametro non definito

    Forse quello che ti serviva era piuttosto

    myHandler(id);
    myRequest = CreateXmlHttpReq();

    ammesso che la variabile myRequest sia definita globalmente. Ma non vedendo il codice sarebbe meglio postare anche la funzione CreateXmlHttpReq e specificare che argomento si aspetta.
    Vuoi aiutare la riforestazione responsabile?

    Iscriviti a Ecologi e inizia a rimuovere la tua impronta ecologica (30 alberi extra usando il referral)

  3. #3
    grazie mille questo è tutto il codice

    <script>
    // Create the XML HTTP request object. We try to be
    // more cross-browser as possible.
    function CreateXmlHttpReq(handler) {
    var agt = navigator.userAgent.toLowerCase();
    var is_ie5 = (agt.indexOf('msie 5') != -1);
    var xmlhttp = null;
    try {
    xmlhttp = new XMLHttpRequest();
    try {
    // Fix for some version of Mozilla browser.
    http_request.overrideMimeType('text/xml');
    } catch(e) { }
    xmlhttp.onload = handler;
    xmlhttp.onerror = handler;
    } catch(e) {
    var control = (is_ie5) ? "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP";
    xmlhttp = new ActiveXObject(control);
    xmlhttp.onreadystatechange = handler;
    }
    return xmlhttp;
    }

    var lastid;

    function myHandler() {
    if (myRequest.readyState == 4 && myRequest.status == 200) {
    var e = document.getElementById(lastid + "last");
    e.innerHTML = myRequest.responseText;
    e.style.color= "red";
    e.style.background= "#FFFF00";
    }

    }

    function controllo(id) {
    var e = document.getElementById(id);
    myRequest = CreateXmlHttpReq(myHandler);
    myRequest.open("GET","registrato.php?controllo=" + e.value + "&campo=" + id );
    myRequest.send(null);
    lastid= id;
    }
    </script>

    <body>

    <table width="462" border="0">
    <tr>
    <td width="168">


    Login </td>

    <td width="176"><input name="Login" type="text" id="login" onblur="controllo(id);" /></td>
    <td width="104"><div id="loginlast"> convalida nome </div>

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.