包括使用jQuery或Javascript PHP文件(Include PHP file using

2019-08-18 05:08发布

我有一个提交表单并加载警报等。现在我想将功能添加到来电或得到一个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);

?>

Answer 1:

我想你可以尝试load()

$("#mailDiv").load('mail.php');

据我$.get$.post是发送数据。 使用这个你不能包含文件。



Answer 2:

您可以使用

$('selector').load() 

要么

$.ajax();

$.ajax(); 是最优选的。



文章来源: Include PHP file using jQuery or Javascript