doujing1858 2016-08-13 22:49
浏览 519
已采纳

在bootstrap模式中提交表单

I have a page using a modal to register new user Here is the modal code :

<div id="register" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">New User</h4>
      </div>
      <div class="modal-body">

      <form id="new_customer" action="../model/php/action.php" method="post">
     <div class="form-group">
  <label for="usr">username:</label>
  <input type="text" name="user" class="form-control" id="usr">
</div>
 <div class="form-group">
  <label for="em">email :</label>
  <input type="text" name="email" class="form-control" id="em">
</div>
<div class="form-group">
  <label for="pwd">password :</label>
  <input type="password" name="pwd" class="form-control" id="pwd">
</div>
        <button type="submit"  id="signup" name="signup" class="btn btn-success btn-lg">signup<span class="glyphicon glyphicon-user"></span></button>
     </form>   </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-info" data-dismiss="modal">close</button>
      </div>
    </div>

  </div>
</div>

and here example action page :

<?php
   if(isset($_POST['signup']))
   {
       if(empty($_POST['user']) || empty($_POST['email']) || empty($_POST['pwd']))
       {
       echo $lang['empty'];
       }
   }
   ?>

i want view back the results in the same dialog.

  • 写回答

1条回答 默认 最新

  • douzhuochao4027 2016-08-13 23:04
    关注

    This ajax request for your question, if you don't understand it read about jquery and ajax requests.

    http://api.jquery.com/jquery.ajax/
    https://learn.jquery.com/

    ajax request it will not call reload of the page, so your modal will still displayed:

    $.ajax({
        type: "POST",
        data: {user: $('#usr').val(), email: $('#em').val(), pwd: $('#pwd').val()},
        url: "/model/php/action.php",
        success: function(data){
              //here data will contain all output from .php, so for your script it will equal to $lang['empty'], you ca do whatever you want with data
              //f.e. set to modal
        },
        error: function(data) {
            console.log(data); //error message
        }
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R
  • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
  • ¥15 八路抢答器设计出现故障
  • ¥15 opencv 无法读取视频
  • ¥15 用matlab 实现通信仿真
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了