我想显示一条消息:“恭喜!你已经注册了”。 但该消息显示在页面的左上角。我想在“提交按钮”下面的同一页面中显示它。 这是我的代码:
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!";
}
答案 0 :(得分:0)
此页面应易于理解,它会告诉您具体操作。 http://net.tutsplus.com/tutorials/javascript-ajax/submit-a-form-without-page-refresh-using-jquery/
答案 1 :(得分: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>