Visualizzazione dei risultati da 1 a 4 su 4
  1. #1
    Utente di HTML.it L'avatar di thitan
    Registrato dal
    Feb 2001
    Messaggi
    716

    sintassi chiamate funzioni

    ciao,
    in uno script ajax, un semplicissimo request, ho le mie tre funzioni
    Codice PHP:
    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;
    }

    function 
    myHandler(cap) {
            if (
    myRequest.readyState == && myRequest.status == 200) {
                    
    document.getElementById("info"+cap);
                    
    e.innerHTML '<span class="link_01_nero">Modifica Effettuata</span>';
                    
    h=document.getElementById("testo"+cap);
                    
    h.value myRequest.responseText;
            }
    }

    function 
    modifica(numhowcosa) {
            var 
    campo document.getElementById("testo"+num);
            var 
    testo campo.value;
            var 
    Math.random();
            
    myRequest CreateXmlHttpReq(myHandler);
            
    myRequest.open("GET","pagina.php?cosa="+escape(cosa)+"&for="+escape(num)+"&how="+escape(how)+"&testo="+escape(testo))
            
    myRequest.send(null);

    il problema è che quando dichiaro
    myRequest = CreateXmlHttpReq(myHandler);
    avrei bisogno che mi passasse alla funzione myHandler il valore 'cosa'..ho provato a scrivere myRequest = CreateXmlHttpReq(myHandler(num));
    ma me lo boccia, l'errore che mi dà è "myRequest is not defined"...
    come posso fare?

    n.b: dimenticavo, nella versione originale la funzione myHandler non aveva variabiloi iniziali, veniva dichiarata così
    function myHandler() {
    [...]
    }

    www.inter-rail.it
    travellers, not tourist
    Is cuma cá mhinice a théann tú ar strae; is é is tábhachtaí gurb áil leat do bhealach a aimsiú arís.

  2. #2
    Utente di HTML.it L'avatar di floyd
    Registrato dal
    Apr 2001
    Messaggi
    3,837
    non si capisce troppo
    forse questo?
    myRequest = CreateXmlHttpReq(function() {myHandler(num)});
    ma non credo che il valore di num venga passato a myHandler
    dovresti memorizzare il valore in una variabile globale per poi chiamarla in myHandler
    (myRequest dovrebbe dare errore in ogni caso, non è dichiarata da nessuna parte)

  3. #3
    Utente di HTML.it L'avatar di thitan
    Registrato dal
    Feb 2001
    Messaggi
    716
    Originariamente inviato da floyd
    non si capisce troppo
    forse questo?
    myRequest = CreateXmlHttpReq(function() {myHandler(num)});
    ma non credo che il valore di num venga passato a myHandler
    dovresti memorizzare il valore in una variabile globale per poi chiamarla in myHandler
    (myRequest dovrebbe dare errore in ogni caso, non è dichiarata da nessuna parte)
    forse mi sono spiegato male.. quando nel codice
    myRequest = CreateXmlHttpReq(myHandler);
    chiamo la funzione CreateXmlHttpReq dandogli come argomento la funzione myHandler, però io avrei bisogno che a myHandler a sua volta abbia un argomento..
    ora provo con myRequest = CreateXmlHttpReq(function() {myHandler(num)}); o con le globali poi ti dico se funzia, grazie

    www.inter-rail.it
    travellers, not tourist
    Is cuma cá mhinice a théann tú ar strae; is é is tábhachtaí gurb áil leat do bhealach a aimsiú arís.

  4. #4
    Utente di HTML.it L'avatar di thitan
    Registrato dal
    Feb 2001
    Messaggi
    716
    myRequest = CreateXmlHttpReq(function() {myHandler(num)})
    funziona
    GRAZIE!!!!

    www.inter-rail.it
    travellers, not tourist
    Is cuma cá mhinice a théann tú ar strae; is é is tábhachtaí gurb áil leat do bhealach a aimsiú arís.

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