这是我要将数据发送到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 :(得分:0)
您的JS代码无效。看看here,看看如何使用$.ajax(...)
:
答案 1 :(得分: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>
答案 2 :(得分: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
}
在AJAX方面,你得到了回应,并评估if是真还是假,然后你决定做什么。
希望能有所帮助。 J.C!