0

我想显示一条消息,例如:“恭喜!您已注册”。但是该消息出现在页面的左上角。我想在“提交按钮”下方的同一页面中显示它。这是我的代码:

if($result)
    {
        //send the email

        $to = "xyz@abc.com";
        $subject = "New order for Weaving Hope";

        //headers and subject
        $headers  = "MIME-Version: 1.0\r\n";
        $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
        $headers .= "From: ".$name." <".$email.">\r\n";

        $body = "New contact<br />";
        $body .= "Name: ".$name."<br />";
        $body .= "Email: ".$email."<br />";
        $body .= "Contact No.: ".$contact."<br />";
        $body .= "Item Id: ".$itemid."<br />";
        $body .= "Quantity: ".$itemquantity."<br />";
        $body .= "Comment: ".$comment."<br />";
        $body .= "IP: ".$ip."<br />";

        mail($to, $subject, $body, $headers);

        //ok message

        echo "Congrats!";
    }
4

2 回答 2

0

这个页面应该很容易理解,它会告诉你该怎么做。 http://net.tutsplus.com/tutorials/javascript-ajax/submit-a-form-without-page-refresh-using-jquery/

于 2012-06-01T02:45:53.460 回答
0

如果您需要在没有 AJAX 的情况下执行此操作,那么您需要在将表单发送到浏览器的同一 PHP 页面中处理表单数据,并设置一个标志来确定数据提交是否成功。

例如:

<?php // Call this page register.php

$success = false;
if( $result)
{
    // .. Your code from above
    $success = true;
}

?>
<form action="register.php" method="post">
    <!-- Output the form for submission here -->
    <input type="submit" name="register" value="Register" />
    <?php if( $success): ?>
        <span>Congrats, you are registered!</span>
    <?php endif; ?>
</form>
于 2012-06-01T02:51:16.047 回答