weixin_33743703 2012-12-26 16:08 采纳率: 0%
浏览 35

使用ajax / jquery进行FORM检查

                <div class="grid--cell fl1 lh-lg">
                    <div class="grid--cell fl1 lh-lg">
                        This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,   or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making   this question more broadly applicable, <a href="/help/reopen-questions">visit the help center</a>.

                    </div>
                </div>
            </div>
            <div class="grid--cell mb0 mt8">Closed <span title="2013-01-18 01:40:36Z" class="relativetime">7 years ago</span>.</div>
        </div>
    </aside>

im trying to send form with ajax and jquery to get result on same page. I have this code,that im linking from my form action :

function check()
{

    var html = $.ajax({
        type: "POST",
        url: "reg.php",
        data: $("#reg").serialize(),
        async: false
        }).responseText;
    if(html == "success") { 


        //Indicate a Successful Captcha
        $("#captcha-status").html("<p class=\"green bold\">Success! Thanks you may now proceed.</p>");
    } else {
        $("#captcha-status").html("<p class=\"red bold\">The security code you entered did not match. Please try again.</p>");

    }
}    

And then i have this rip of my php file :

$query = "SELECT * FROM teemo1 WHERE nick='$nick' and server='$server'";
$result = mysql_query($query) or die(mysql_error());

if (mysql_num_rows($result) )
{
    echo 'success';
}
else
{
$queryy =  

     echo 'fail';
}

 }

I need to show in my page with form "Data successfully saved" and if fail "Incorrecta data", but i dont know how to get those echos from php file to my ajax script.

Thanks

</div>
  • 写回答

2条回答 默认 最新

  • weixin_33712881 2012-12-26 16:13
    关注

    try this :

    function check(){
        $.ajax({
        type: "POST",
        url: "reg.php",
        data: $("#reg").serialize(),
        async: false,
        success:function(html){
            if(html == "success") { 
                $("#captcha-status").html("<p class=\"green bold\">Success! Thanks you may now proceed.</p>");
            } else {
                $("#captcha-status").html("<p class=\"red bold\">The security code you entered did not match. Please try again.</p>");
                }
            }
        });
    }   
    
    评论

报告相同问题?

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler