Pagina 1 di 3 1 2 3 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 22
  1. #1

    Far partire due funzioni consecutivamente

    Ciao,
    ho la necessità di far partire 2 funzioni ahah uguali al click su un menu, perchè ogni funzione aggiorna un div.

    ho provato così:

    function ajax(url1, target1, url2, target2, parameters) {
    ahah(url1, target1, 5, "POST", parameters);
    setTimeout("ahah('"+url2+"','"+target2+"',5,'POST' ,'"+parameters+"')", 1500);
    }

    purtroppo a volte la prima chiamata si perde, o ci mette più tempo, quindi la seconda quando parte la va a sovrascrivere (carica url2 in entrambi i div).

    Come posso far partire la seconda chiamata solo quando la prima è conclusa? Il setTimeout non mi interessa, l'ho messo solo perchè vi è questo problema.

  2. #2

  3. #3
    sembra di si, almeno leggendo, ma non ho ben capito come applicarlo...

    - Quella funzione sostituisce entrambe le funzioni ahah() e ahahDone()?
    - Si può usare anche con il POST?
    - Devo richiamare ahah() come solito o __ahah()?

  4. #4
    Comunque no, non è stato risolto con l'ultima versione completeAHAH.
    La tua variante come si applica?

  5. #5
    Risolto!
    E' bastato rendere locale la variabile req con var req, e poi passarla come parametro a ahahDone... semplice, bastava arrivarci!

  6. #6
    Originariamente inviato da Why?
    Risolto!
    E' bastato rendere locale la variabile req con var req, e poi passarla come parametro a ahahDone... semplice, bastava arrivarci!
    non era difficilissimo, è la prima cosa scritta nei links che ti ho postato
    ... comunque magari postala la tua variante così anche altri potranno sfruttarla
    Formaldehyde a new Ajax PHP Zero Config Error Debugger

    WebReflection @WebReflection

  7. #7
    Utente di HTML.it L'avatar di pietro09
    Registrato dal
    Jan 2002
    Messaggi
    10,116
    Originariamente inviato da andr3a
    non era difficilissimo, è la prima cosa scritta nei links che ti ho postato
    ... comunque magari postala la tua variante così anche altri potranno sfruttarla
    Scusate l'intromissione : vorrei chiedere ad Andrea se ha un test semplice in c# o basic per collaudare funzioni ajax. Ciao
    Pietro

  8. #8
    la funzione che ho usato è semplicemente quella standard.
    Ho inserito var prima della dichiarazione di ogni req.
    Ovvimente in questo modo la funzione ahahDone non conosce req (diventa locale), quindi ho passato req come parametro di ahahDone.


    var completeAHAH = {

    loading : '<div align="center">
    [img]img/loading.gif[/img]</div>',

    ahah : function (url, target, delay, method, parameters) {

    if ( ( method == undefined ) || ( method == "GET" ) || ( method == "get" ) ){

    this.creaDIV(target, this.loading);

    if (window.XMLHttpRequest) {
    var req = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
    var req = new ActiveXObject("Microsoft.XMLHTTP");
    }
    if (req) {
    req.onreadystatechange = function() {
    completeAHAH.ahahDone(url, target, delay, method, parameters, req);
    };
    req.open(method, url, true);
    req.send("");
    }
    }
    if ( (method == "POST") || (method == "post") ){

    this.creaDIV(target, this.loading);

    if (window.XMLHttpRequest) {
    var req = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
    var req = new ActiveXObject("Microsoft.XMLHTTP");
    }
    if (req) {
    req.onreadystatechange = function() {
    completeAHAH.ahahDone(url, target, delay, method, parameters, req);
    };
    req.open(method, url, true);
    req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    req.send(parameters);
    }
    }
    },

    creaDIV : function (target, html){

    if (document.body.innerHTML){
    document.getElementById(target).innerHTML = html;
    }
    else if (document.getElementById){
    var element = document.getElementById(target);
    var range = document.createRange();

    range.selectNodeContents(element);
    range.deleteContents();
    element.appendChild(range.createContextualFragment (html));

    }
    },

    ahahDone : function (url, target, delay, method, parameters, req) {
    if (req.readyState == 4) {
    element = document.getElementById(target);
    if (req.status == 200) {
    this.creaDIV(target, req.responseText);
    }
    else {
    this.creaDIV(target, "ahah error:\n"+req.statusText);
    }
    }
    },

    /*

    @@ parameters :
    fileName = name of your cgi or other
    method = GET or POST, default is GET
    formName = name of your form
    dynamicTarget = name of your dynamic Target DIV or other

    @@ usage :
    <form id="formName" action="javascript:completeAHAH.likeSubmit('fileNa me', 'method', 'formName', 'dynamicTarget');">

    */

    likeSubmit : function ( file, method, formName, target ) {

    var the_form = document.getElementById(formName);
    var num = the_form.elements.length;
    var url = "";
    var radio_buttons = new Array();
    var nome_buttons = new Array();
    var check_buttons = new Array();

    // submit radio values
    var j = 0;
    var a = 0;
    for(var i=0; i<the_form.length; i++){
    var temp = the_form.elements[i].type;
    if ( (temp == "radio") && ( the_form.elements[i].checked) ) {
    nome_buttons[a] = the_form.elements[i].name;
    radio_buttons[j] = the_form.elements[i].value;
    j++;
    a++;
    }
    }
    for(var k = 0; k < radio_buttons.length; k++) {
    url += nome_buttons[k] + "=" + radio_buttons[k] + "&";
    }

    // submit checkbox values
    var j = 0;
    var a = 0;
    for(var i=0; i<the_form.length; i++){
    var temp = the_form.elements[i].type;
    if ( (temp == "checkbox") && ( the_form.elements[i].checked) ) {
    nome_buttons[a] = the_form.elements[i].name;
    check_buttons[j] = the_form.elements[i].value;
    j++;
    a++;
    }
    }
    for(var k = 0; k < check_buttons.length; k++) {
    url += nome_buttons[k] + "=" + check_buttons[k] + "&";
    }

    // submit all kind of input
    for (var i = 0; i < num; i++){
    var chiave = the_form.elements[i].name;
    var valore = the_form.elements[i].value;
    var tipo = the_form.elements[i].type;

    if ( (tipo == "submit") || (tipo == "radio") || (tipo == "checkbox") ){}
    else {
    url += chiave + "=" + valore + "&";
    }
    }

    var parameters = url;
    url = file + "?" + url;

    if (method == undefined) {
    method = "GET";
    }
    if (method == "GET") {
    this.ahah(url, target, '', method, '');
    }
    else {
    this.ahah(file, target, '', method, parameters);
    }
    }

    };

  9. #9
    Altra cosa, io ci sono cascato ma sicuramente voi siete più avanti.
    la funzione submit di ahah vuole che si specifichi il form con id:
    <form id="news" name="news">
    Altrimenti funziona solo con explorer.

  10. #10
    Utente di HTML.it L'avatar di semolino
    Registrato dal
    Nov 2004
    Messaggi
    1,499
    Scusa ma ora come richiami la funzione per caricare i contenuti nelle due div? Come imposti il codice?

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.