Jquery ajax php只工作一次

afr*_*360 1 php jquery

我有以下jQuery

        $("button#submit").click(function(){
            $.ajax({
                type: "POST",
                url: "process.php",
                data: $('form.contact').serialize(),
              success: function(msg){
                $("#form-content").modal('hide');                     
                $("#thanks").html(msg);
                $("#thanks").delay(2000).fadeOut("slow");
              },
                error: function(){
                    alert("failure");
                }
            });
        });
Run Code Online (Sandbox Code Playgroud)

和Php

<?php
    if (isset($_POST['name'])) {
    $name = strip_tags($_POST['name']);
    $email = strip_tags($_POST['Email']);
    $sug = strip_tags($_POST['sug']);

    echo "<span class='label label-info'>Your Website has been submitted .. Thank you</span>";
}?>
Run Code Online (Sandbox Code Playgroud)

这是第一次工作,并在我的页面上显示php echo.但是,当我再次提交表格时,它没有显示.

vic*_*lim 5

你的$("#thanks")dom是隐藏的.

    $("button#submit").click(function(){
        $.ajax({
            type: "POST",
            url: "process.php",
            data: $('form.contact').serialize(),
          success: function(msg){
            $("#form-content").modal('hide');                     
            $("#thanks").html(msg);
            $("#thanks").show();  <----------------ADD THIS
            $("#thanks").delay(2000).fadeOut("slow");
          },
            error: function(){
                alert("failure");
            }
        });
    });
Run Code Online (Sandbox Code Playgroud)