用jQuery在while循环中调用模态

时间:2018-06-23 22:32:03

标签: php jquery html ajax bootstrap-modal

我在php的while循环表中有一个模态,以显示一些值,并有机会通过JQuery ajax将它们发送到edit.php来更改这些值,并警告成功消息...但是问题是当我只运行第一行中的模态代码,将更改发送到edit.php并发送成功消息,而不发送其他消息。我在做什么错了?

  

PHP

while($row=sqlsrv_fetch_array($stmt)
{ 
$id = $row[0]; $name=$row[1]; 
echo"<tr>"; 
echo"<td>".$name[1]."</td>"; 
echo"<td>";
  

html模态

<a href="#EditModal<?php echo $id ?>" role="button" class="btn btn-warning" data-toggle="modal">Edit</a>

<div class="modal fade" id="EditModal<?php echo $id; ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel<?php echo $id; ?>" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
...
    <form class="form-horizontal">
      <div class="modal-body">
       <div class="container text-center">
        <div class="form-group">
         <input type="hidden" name="edit_modal_id" value="<?php echo $id; ?>">
          <div class="col-sm-5"> <label>Id category :</label> </div>
          <label id="idcategory" name="idcategory" ><?php echo $id; ?>
          <div class="xs-5"> <label>name category : <label> </div>
          <input type="text" class="form-control" id="editedname" name="editedname" placeholder="<?php echo $name; ?> ">
        </div>
      </div>
     </div>
    <div class="modal-footer">
    <button type="button" class="btn btn-primary" id="editbutton" name="editbutton" >Save</button>
    </div>
  </form>
 </div>
</div>
</div>
</td>
</tr>
?>
  

JQuery- Ajax

 <script>
 $(document).ready(function)(){
 $("#editbutton").click(function(){
 var new_name = $("#editname").val();
 var id_category = $("idcategory").val();
 console.log(new_name);
 if(new_name == ""_
 { alert('give a name'); }
 else
  { 
  $.post("edit.php",{suggestion: new_name, keys: id_category, type:'POST', async:false},function(data,status) { alert(data); });
  }
  });
  });

0 个答案:

没有答案