头上的基本标签使ajax无法工作

时间:2014-04-14 01:01:44

标签: php ajax base head

为了缩短它,我会说这个,我正在进行一些调试,我发现头上的标签使得ajax无法工作。我有这个代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<base href="http://localhost/PaolaBoutique/">
<title>Untitled Document</title>
</head>

<body>

<?php
 include('fromincluded.php');
?>

<script type="text/javascript">


$(document).ready(function(e) {
    $("#testform").submit(function(e){
            e.preventDefault();
            $.post( "fromtest.php", $( "#testform" ).serialize() )
            .done(function(data) {
            document.getElementById("errormsg").innerHTML = data;       
            }); 

        });
});


</script>

</body>
</html>

fromincluded.php

<form id="testform" method="post">
<input name="to" type="text" />
<input name="from" type="text" />
<textarea name="body" rows="10"></textarea>
<div id="errormsg"></div>
<input name="send" type="submit" value="send" />
</form>

来自test.php的phpmailer的最终代码

<?php

//error_reporting(E_ALL);
error_reporting(E_STRICT);

date_default_timezone_set('America/Toronto');

require_once('../../PHPMailer_v5.1/class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

$mail             = new PHPMailer();

$body             = file_get_contents('contents.html');
$body             = eregi_replace("[\]",'',$body);

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host       = "smtpout.secureserver.net"; // SMTP server
$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                                           // 1 = errors and messages
                                           // 2 = messages only
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->Host       = "smtpout.secureserver.net"; // sets the SMTP server
$mail->Port       = 25;                    // set the SMTP port for the GMAIL server
$mail->Username   = "usr"; // SMTP account username
$mail->Password   = "password";        // SMTP account password

$mail->SetFrom($_POST["from"], 'First Last');

$mail->AddReplyTo($_POST["from"],"First Last");
$mail->AddAttachment("images/phpmailer.gif");      // attachment
$mail->Subject    = "PHPMailer Test Subject via smtp, basic with authentication";

$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

$mail->MsgHTML($_POST["body"]);

$address = $_POST["to"];
$mail->AddAddress($address, "John Doe");

if(!$mail->Send()) {
  die( "Mailer Error: " . $mail->ErrorInfo);
} else {
  echo "Message sent!";
}

?>

当我从php主文件中删除标签时,ajax工作,任何人都有这方面的经验,并向我解释发生了什么,如果我犯了一个代码错误。

谢谢

0 个答案:

没有答案