0

在我的联系表单上单击“提交”后,我想使用 AJAX 将我的内容加载success.html到一个 div 中(类似于我网站的其他部分),但我在确定为此使用哪个特定 AJAX/jQuery 时遇到了问题。

我正在努力:

$("#submitButton").click(function(){
    $("#mainImage").load("success.html");
});

但无济于事。

这是我用来将网站的其余部分加载到#mainImagediv 中的 AJAX:

$("#thumbs div").click(function(){             
    var toLoad = $(this).children('a').attr('href')+' #mainImage';
    $('#mainImage').fadeOut("fast",loadContent);
    window.location.hash = $(this).children('a').substr(0,$(this).children('a').length-5);
    function loadContent() {
        $('#mainImage').load(toLoad,'',showNewContent())
    }
    function showNewContent() {
        $('#mainImage').fadeIn("1000");
    }
    return false;
});

这是我success.html在点击“提交”后直接访问的 PHP 表单。

<?php
ob_start();

if(isset($_POST['submit'])) { 
    $to =  "shubba4142@gmail.com";
    $subject = "BP Contact Form";
    $name_field = $_POST['name'];                
    $email_field = $_POST['email']; 
    $phone_field = $_POST['phone'];                            
    $message = $_POST['message'];
    $body = "From: $name_field\n E-Mail: $email_field\n Phone: $phone_field\n         Message:\n $message"; 
    $success = mail($to, $subject, $body);
}

if (mail($to, $subject, $body)){
    header("location:/BP%20SITE-SHD/success.html");
} 

else {
    header("location:/BP%20SITE-SHD/error.html");
}

?>

谢谢!!

4

0 回答 0