doushi3189 2013-07-24 07:04
浏览 43
已采纳

数据库中的异步请求[关闭]

There is a code:

<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>

And that: 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 " %";
}
?>

So, is it possible to get request in database without submit the form and redirect to new page (step2.php in this example)? I mean, query result is shown immediately.. I think about onBlur() method, but I don't know how create similar request with JavaScript. Maybe it is possible with AJAX?

I would be grateful for any advice. Thx a lot.

  • 写回答

3条回答 默认 最新

  • doudundian9558 2013-07-24 07:18
    关注

    in your <head>

    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    
    <script>
    function jqAjaxForm(data2send, file2send, dataConteiner) { 
    
        if(data2send.indexOf("#") != -1){
            data2send = jQuery(data2send).serialize();
        }
    
        jQuery(dataConteiner).html("<option>Loading...</option>");
        jQuery.ajax({
            type    : "POST",
            url     : file2send,
            data    : data2send,
            success : function(data){ jQuery(dataConteiner).html(data); },
            error   : function(data){ jQuery(dataConteiner).html(data); },
            cache   : false
        });
    
    }
    </script>
    

    instead in your body

    <body>
        <div id="target"><div>
        <form name="step1" action="step2.php" method="POST" id="form">
            Email: <input type="text" name="email" class="input-medium">
            <button class="btn btn-small btn-warning" type="submit" on click = "jqAjaxForm('#form', 'step2.php','#target')">Check</button> 
        </form>
    </body>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办