2017-09-02 35 views
0

這是我從哪裏將數據發送到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

回答

0

您的JS代碼無效。看看here,怎麼看$.ajax(...)用於:

0

試着改變你的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> 
0

男人,我看到的是在接收代碼的問題。 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!

相關問題