簡體   English   中英

使用jQuery post方法檢索數據時,單擊按鈕時未提交表單

[英]form is not submitting when click on button, when data retrieved using jquery post method

我正在使用ajax post方法檢索數據,它的檢索結果是整個表顯示在分區中。在帶有表單的表按鈕中,當單擊按鈕的表單未提交到目標文件時,其重定向到同一頁。 請任何人能幫助我嗎? 對我有用。 代碼如下:

 **jquery**
  $("#search").keyup(function(e) {
  var val=$(this).val();
   if(val=='')
   {
       //alert("empty");
       $("#resp").hide("");

   }
   else
   {
     $.post("search_db.php",{search:val},function(response){
     $("#resp").show("");
     $("#resp").html(response);
     });
   }
 });     

  **search_db.php**
  <tr align="center">
    <td><?php echo $i;  ?></td>
    <td><?php echo $rows['acc_num'];  ?></td>
    <td><?php echo $rows['cust_name'];  ?></td>
    <td><a href="tel:<?php echo $rows['phone_code'].$rows['contact']; ?>"><?php echo $rows['phone_code'].$rows['contact'];  ?></a></td>
    <td><?php echo $row_bal['bal'];  ?></td>
     <td><form action="account_statement.php" method="post"><input type="hidden" name="hide_id" value="<?php echo $rows['acc_num']; ?>" /><input type="hidden" name="hide_search" value="<?php echo $_POST['search']; ?>" /><button type="submit" class="btn btn-info">View</button></form></td>
 </tr>

 **Html**
<form action="search.php" method="post">
<div id="number"  style="padding-right:15px;">
   <div class="form-group" >
      <label class="control-label">Search</label><label id="error_search"></label>
      <input type="text" name="search" id="search" placeholder="Name or Phone or Place" required class="form-control" />
   </div>
</div>



您是否嘗試過完整路徑..?

例如: http : //www.example.com/account_statement.php

要么

簡單放置在account_statement.php之前

因此您的表單action屬性類似於action =“ / account_statement.php”

考慮這張桌子

<table id="table">
     <tr>
          <td>...1</td>
     </tr>
</table>

只需替換div id

$("#resp").html(response);
or
//document.window.reload(); //if u want reload

要么

您也可以使用插件(js插件)

數據表(請參閱本頁)

https://datatables.net/examples/styling/display.html

使用<input type="submit" />代替<button type="submit"> 如果您以html形式使用<button> ,則某些瀏覽器將無法正常運行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM