有一个代码:
<form name="step1" action="step2.php" method="POST">
Email: <input type="text" name="email" class="input-medium">
<button class="btn btn-small btn-warning" type="submit">Check</button>
</form>
那就是:step2.php
<?php
$email = $_POST['email'];
$result = mysql_query("SELECT email,discount FROM buyers WHERE email='$email'");
if (mysql_num_rows($result) <= 0)
{
echo "Are you a new client is't it? <br>";
echo "Your discount is 0%<br>";
}
else{
echo "<br/>Nice to see you again! <br/>";
$getSalary = mysql_fetch_array($result);
echo "You discount is already: ";
echo $getSalary[discount];
echo " %";
}
?>
那么,是否可以在不提交表单并重定向到新页面的情况下在数据库中获取请求(本例中为 step2.php)?我的意思是,查询结果会立即显示出来。我想到了 onBlur() 方法,但我不知道如何使用 JavaScript 创建类似的请求。也许使用 AJAX 是可能的?
我将不胜感激任何建议。多谢。