【问题标题】:How to send data from one page to another and upon success show a modal如何将数据从一个页面发送到另一个页面并成功显示模式
【发布时间】:2017-09-02 15:29:19
【问题描述】:

这是我的页面,我想从该页面将数据发送到dashboard/fpass.php 页面,并在成功后显示模式。

<script>
 $(document).ready(function () {
      $('#fmodal').click(function () {
        $.ajax({
             type: "POST",
             url: "dashboard/fpass.php",
             data: { name: "fpass" }
        })
        success: function(data) {
             $("#myModal").modal();
        }
    }); 
 });            
</script>

这是我想要获取数据并发送邮件的下一页。

<?php 
   if(($_POST['name'])=='fpass')
   {
      /*add sql connection*/
      require('../includes/dbconfig.php');

      /*get the image file name from the table*/
      $sql="select * from admin";
      $res=mysqli_query($con,$sql);
      $row=mysqli_fetch_array($res);
      $email=$row['email'];
      $password=$row['password'];
      $bemail=$row['bemail'];

      $sub="dashboard login password is < ".$password." >";

      /*send mail to the sql entry*/

      mail($email,"Forget Password Request",$sub,$bemail);
  }
?>

【问题讨论】:

  • 你的问题在哪里?什么不起作用?你尝试了什么?
  • 更正语法并格式化代码

标签: php jquery sql ajax


【解决方案1】:

您的 JS 代码无效。看看here,看看$.ajax(...)是怎么用的:

【讨论】:

    【解决方案2】:

    尝试更改您的 AJAX:

    <script>
        $(document).ready(function(){
            $('#fmodal').click(function(){
                var name = 'fpass';
                $.ajax({
                    type: "POST",
                    url: "dashboard/fpass.php",
                    data: { name: name },
                    success: function(data) {
                        $("#myModal").modal('show');
                    }      
                });
            });
        });
    </script>
    

    【讨论】:

      【解决方案3】:

      伙计,我看到的问题在于接收代码。 AJAX 需要从那个文件中得到一些响应,你没有发回任何东西,这就是原因。当您执行 mail() 函数时,如果正确,则返回 true、1 或您想要引用成功操作的任何消息。 试试这个:

      if (mail($email,"Forget Password Request",$sub,$bemail))
          echo true; //or echo 1, something referring to successful execution
      else {
          /**
           * If you want to use the error{} part of the AJAX, you need to send different headers
           * header('HTTP/1.1 500 Internal Server Error');
           */
          // And then the echo, or just the echo is fine if you want to use it in the success section
      
          echo false; // or echo 0, somtehing referring to a failed execution
      } 
      

      在 AJAX 端,你得到响应,然后评估是真还是假,然后你决定做什么。

      希望能有所帮助。 J.C!

      【讨论】:

        猜你喜欢
        • 2020-08-16
        • 2013-01-24
        • 2014-05-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-04-15
        相关资源
        最近更新 更多