Ajax返回整页作为响应

时间:2019-07-31 04:14:04

标签: php jquery ajax

我有一个使用户输入Id并通过if条件检查ID的网站,它可以正常工作,但是我想由Ajax进行验证,所以我如何使用User输入的ID并通过if条件传递它而又没有提神?能做到吗,或者我错过了什么

我试图通过邮寄获得ajax响应,但它会响应所有页面内容

 // My PHP Code 
  <?php
   if(isset($_POST['Sub'])){
    if(!empty($_POST['Id'])){
      $BlockedRows =
      RowCountDB("Id","blocked","TeacherId",
      $TeacherId['Id'],"StudentId",$_SESSION['Id']);
      if($BlockedRows == 0){ //Not Blocked 
        InsertDB("registerduserstid","UserId",
         $_SESSION['Id'],"TeacherId",$Id);
       }else{ //Blocked
      ?>
        <div class="alert alert-danger alert-dismissible"><a href='#' 
         class='close' data-dismiss='alert' aria-label='close'>&times</a> 
        <b>You are Blocked!</b></div>
        <?php
         }
      }   
   }
  ?>
 // My HTML Code
  <form id="TeachersMenuForm" class="form" action="Home.php? 
    task=TeachersMenu" method="post">
     <div class="row">
        <div class="col-8">
           <i class="far fa-id-badge Id"></i>
           <input type="text" class="Input form-control TeacherID" 
           placeholder="Id" name="Id">
         </div>
         <div class="col-2.5">
           <button name="Sub" class="btn btn-md btn-primary"><i 
           class="fas fa-plus"></i> Enter</button>
          </div>
        </div>
 </form>
 // My Ajax Code
  $("#TeachersMenuForm").on('submit', function () {
    var Url = $(this).attr("action"),
        Type = $(this).attr("method"),
        Id = $(".TeacherID").val();
    $.post({
        type: Type,
        data: "Id="+Id,
        url: Url,
        success: function (response) {
            console.log(response);
        }
    });
    return false;
});

我希望得到用户输入的ID的响应

0 个答案:

没有答案