提交后,ajax不会在js的表单下返回控制权

时间:2016-10-25 09:25:53

标签: javascript jquery ajax forms

Bellow是我从类别列表中提交表单的代码。列表中的所有按钮填充一个表单,并且在使用ajax提交表单之前它可以正常工作。 ajax提交后,没有一个按钮可以再次填写表格。 我可以再次用手填表并再次发送,但如果我想用JS(点击按钮)这样做,那么我只能获得旧数据的表格。

$(function(){

   $("#categories span.addsubcategory").click(function(){
       $("#category-action").text("Add category: "+$(this).parent().children().eq(0).text());
       $("#parentcategoryid").val($(this).parent().attr('data-catid'));
       $("#ajaxaction").val('addsubdir');
       $("#categoryname").val('');
       $("#categoryname").prop("disabled", false);
   })

      $("#categories span.renamecategory").click(function(){
          $("#category-action").text("Rename category");
       $("#parentcategoryid").val($(this).parent().attr('data-catid'));
       $("#ajaxaction").val('renamedir');
       $("#categoryname").val($(this).parent().children().eq(0).text());
          $("#categoryname").prop("disabled", false);
   })

      $("#categories span.deletecategory").click(function(){
          $("#category-action").text("Delete category");
       $("#parentcategoryid").val($(this).parent().attr('data-catid'));
       $("#ajaxaction").val('deletedir');
       $("#categoryname").val($(this).parent().children().eq(0).text());
          $("#categoryname").prop("disabled", true);
   })

 $("#newcategory").submit(function sendCategory(){
          $.ajax({
                type: "POST",
                url: "index.php",
                data: $("#newcategory").serialize(),
                success: function(response){
                        $("#categories .panel-body").html(response);
                        } ,
                error: function(){
                    alert("Data sending error");
                },
             complete: function(data) { 
                    $("#newcategory").find('input[type="submit"]').prop('disabled', false); 
                    $("#adddir").modal('hide');
                 }
         });
          return false;
         }); 

});

1 个答案:

答案 0 :(得分:0)

Delegate所有点击事件

$("body").on("click","#categories span.deletecategory",function(){

  //code
});