jqueryajaxphp只工作一次

jqueryajaxphp只工作一次,php,jquery,Php,Jquery,我有以下jQuery $("button#submit").click(function(){ $.ajax({ type: "POST", url: "process.php", data: $('form.contact').serialize(), success: function(msg){

我有以下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");
                }
            });
        });
和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>";
}?>
您的
$(“#谢谢”)
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");
            }
        });
    });
$(“按钮提交”)。单击(函数(){
$.ajax({
类型:“POST”,
url:“process.php”,
数据:$('form.contact')。序列化(),
成功:功能(msg){
$(“#表单内容”).modal('hide');
$(“#谢谢”).html(msg);
$(“#谢谢”).show();您的
$(“#谢谢”)
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");
            }
        });
    });
$(“按钮提交”)。单击(函数(){
$.ajax({
类型:“POST”,
url:“process.php”,
数据:$('form.contact')。序列化(),
成功:功能(msg){
$(“#表单内容”).modal('hide');
$(“#谢谢”).html(msg);
$(“#谢谢”).show();使用
.on()

使用
.on()

像这样使用

$("button#submit").live('click', function(e) {
  $.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");
            }
        });
    });
检查此处的差异
.live
.on
像这样使用

$("button#submit").live('click', function(e) {
  $.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");
            }
        });
    });
检查此处的差异
.live
.on

如果你能把它放在JSFIDDLE中,你的美元(“#谢谢”)会隐藏得更好如果你能把它放在JSFIDDLE中,你的美元(“#谢谢”)会隐藏得更好('click')上的
点击
@undefined,兄弟,但是('click')上的
没有区别
word作为委托并处理动态加载的内容。不,这不是事件委托使用的方式,它只是一个常规处理程序。@据我所知,它的行为与我所说的一样未定义。……如果我错了,请纠正我,这样我以后就不会出错。
$(“#staticElement”)。on('click','dynamicallyGeneratedElement',function(){})
在('click')
上的
和('click')上的
没有区别,但是('click')上有….
word作为委托并处理动态加载的内容。不,这不是事件委托使用的方式,它只是一个常规处理程序。@据我所知,它的行为与我所说的一样未定义。……如果我错了,请纠正我,这样我以后就不会出错。
$(“#staticElement”)。on('click','dynamicallyGeneratedElement',function(){})