我有一个提交表单并加载警报等的 Javascript 文件。现在我想添加调用或获取.php
文件的功能,我尝试使用$.get("mail.php");
但它似乎不起作用。
Javascript代码:
$('#myform').on('submit', function(e){
e.preventDefault();
$.get($(this).attr('action') + $(this).serialize());
alert("Thank You! \nTop Up for: <?php echo "$username" ?> Purchased Successfully");
$.get("mail.php"); //this is the added part to get mail.php//
location.reload();
PHP - mail.php
:
<?php
$to = "stephan@mail.co.za";
$headers = "From: website mail \r\n";
$email_body = "has just toped up his account.\n".
$email_subject = "User Topup Alert";
mail($to,$email_subject,$email_body,$headers);
?>