Ajax调用嵌套的php文件

时间:2016-04-07 06:09:06

标签: php ajax

我正在对ajax文件发出POST php个请求。让我们称之为A.php

A.php文件将调用B.php

$.ajax({
            type: "POST",
            url: "../../page_components/A.php",
            data: { // my data
            },
            success: function(response) {
                location.reload();
            },

面临问题:当A.php也调用B时,不会调用成功函数。如果A.php没有调用B.php

,它可以正常工作

在我的A.php

/* some stuff that a.php does
*/
include ('B.php'); // call B.php to handle other stuff

B.php

<?php

require '../../../../PHPMailer/class.phpmailer.php';
require '../../../../PHPMailer/class.smtp.php';

// set relevant agency email to send to. $agency comes from A.php
switch ($agency) {
    case "1": $receiverEmail = "xxx@hotmail.com";
    break;
    case "2" : $receiverEmail = "zzz@gmail.com";
    break;
}


$mail = new PHPMailer();

// All the mail setting and stuff is here...
if(!$mail->Send()) {
  echo 'Message was not sent.';
  echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
  echo 'Message has been sent.';
}
?>

1 个答案:

答案 0 :(得分:-1)

url: "../../page_components/A.php"

该网址是否应该在B.php上发送? 如果它不是那个url应该是这样的

url: "../../page_components/B.php"