如何将数据从一个页面发送到另一个页面,并成功显示模式

问题描述:

这是我从哪里将数据发送到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); 
    } 
?> 
+0

你的问题在哪里?什么不行?你尝试了什么? – VeNoMiS

+0

更正了语法并对代码进行了格式化 – Vega

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

试着改变你的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> 

男人,我看到的是在接收代码的问题。 AJAX需要从那个文件得到一些回应,你没有发回任何东西,这就是为什么。当你执行mail()函数时,如果CORRECT,则返回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 
} 

在阿贾克斯,你得到的响应,并评估是否是真的还是假的,然后你决定做什么。

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