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

    [jquery] ajax e risposta html

    Salve a tutti,

    sto usando da poco jquery e mi trovo di fronte ad un problema.

    ho un form che invia tramite ajax i valori dei campi ad una pagina php, la pagina php interpreta i dati e reinvia la richiesta html

    se i dati vanno bene inserisce nel database e rimanda la risposta : "ok".

    Fin quì tutto bene

    se i dati non vanno bene, ed è quì che sorge il problema, rimando lo stesso identico form html che a quel punto non mi viene più interpretato dal javascript, come se non lo vedesse e se clicco su invia mi parte il form normalmente e non più come ajax

  2. #2
    vi faccio un esempio pratico perchè proprio non riesco a capire... sicuramente sbaglio io ma se è un problema di jquery è grave...

    ho la pagina con il javascript jquery che fa la richiesta ajax:

    Codice PHP:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <
    html xmlns="http://www.w3.org/1999/xhtml">
        <
    head>
            <
    meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
            <
    titleJquery test </title>
            <
    link rel="stylesheet" type="text/css" href="/style.css" />    
            <
    script type="text/javascript" src="/js-fwk/jquery.js"></script>
            <script type="text/javascript">

                var htmlupd = '';

                function onStartLoading() {
                    alert('onStartLoading');         
                }
                function onSuccess(msg) {
                    $("#contenuti").remove();
                    htmlupd = msg;
                    $("#udt").html(htmlupd);
                }
                function onError(xhr, st, er) {
                    alert(er);         
                }
                function ajaxInit(){
                        $.ajaxSetup({
                            url : 'test.php',
                            type : "POST",
                            dataType : "html",
                            beforeSend : onStartLoading,
                            success: onSuccess,
                            error : onError
                        });
                        $.ajax({  data: "nameCat=prova" } );
                }
                $(document).ready( function () {

                    $('#sendr').click(function() {
                        ajaxInit();
                        return false;
                    });

                });
            </script>
        </head>
        <body>
            <div id="udt">
                <div id="contenuti">
                da richiedere...
                <button id="sendr">PREMI</button>
                </div>
            </div>
        </body>
    </html> 

    e la pagina di prova test.php:

    Codice PHP:
    <?php 
    echo '
        <div id="contenuti">
        Richiesta:  '
    .$nameCat.
        <button id="sendr">PREMI</button>
        </div>
        '
    ;
    ?>
    quando premo il bottone la richiesta ajax parte, il div si aggiorna ma se poi ripremo sul pulsante aggiornato la richiesta non parte più

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.