ajax调用后表单提交按钮不起作用

时间:2014-07-15 16:55:23

标签: javascript php jquery mysql ajax

HTML:

<section class="load_schedule">
       <!-- (PHP goes here) --> 
</section>

PHP:

<table id="data_schedule" border="1">
<?php
    while ($row = $result->fetch_assoc()) {
        $sched_id = $row['sched_id'];
        $prof_id = $row['prof_id'];
        $subject_code = $row['subject_code'];
        $subject_name = $row['subject_name'];
        $subject_course = $row['subject_course'];
        $subject_day = $row['subject_day'];
        $subject_time = $row['subject_time'];
        $subject_year = $row['subject_year'];
        $subject_section = $row['subject_section'];
        $subject_room = $row['subject_room'];
        echo "<tr>";
        echo "<form action='delete_schedule.php' method='POST' id='delete_submit_form'>";
        echo "<td><input type='text' name='sched_id' value='" . $sched_id . "'></td>";
        echo "<td><input type='text' name='prof_id' value='" . $prof_id . "'></td>";
        echo "<td>" . $subject_code . "</td>";
        echo "<td>" . $subject_name . "</td>";
        echo "<td>" . $subject_course . "</td>";
        echo "<td>" . $subject_day . "</td>";
        echo "<td>" . $subject_time . "</td>";
        echo "<td>" . $subject_year . "</td>";
        echo "<td>" . $subject_section . "</td>";
        echo "<td>" . $subject_room . "</td>";
        echo "<td><input id='delete_button' type='submit' value='Delete Schedule'></td>";
        echo "</form>";
        echo "</tr>";
    }
?>
</table>

SCRIPT:

$("#delete_submit_form").on("submit", function(event) {
  event.preventDefault();

  if ($(".add_required").val() == ""){
    alert("Please Select Subject Code");
    return false;
  }

  else{
    $.ajax({
      type: "post",
      url: "delete_schedule.php",
      data: $(this).serialize(),
      success: function(){
        $(".add_required").val("");
      },
      error:function(x,e){
          if(x.status==0){
              alert('You are offline!!\n Please Check Your Network.');
          }else if(x.status==404){
              alert('Requested URL not found.');
          }else if(x.status==500){
              alert('Internel Server Error.');
          }else if(e=='parsererror'){
              alert('Error.\nParsing JSON Request failed.');
          }else if(e=='timeout'){
              alert('Request Time out.');
          }else {
              alert('Unknow Error.\n'+x.responseText);
          }
      },
      complete: function() {
        $(".load_schedule").load("load_schedule.php #data_schedule");
      }
    });
  } 
});
加载到主文件(127.0.0.1/index.php)后,

提交按钮不起作用,但如果单独加载,例如:127.0.0.1/load_schedule.php删除按钮正常工作并传递给delete.php < / p>

其他问题: 如何在不刷新页面的情况下至少删除或修改SQL数据?

0 个答案:

没有答案