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 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器