doubeng9407 2011-03-26 19:18
浏览 40
已采纳

结合PHP和jQuery验证

I have a form (for password reset) that first validates that the input is a correct email, then it should look for that email's existence in my user database, and finally reset the password and email the user the new one.

I'm able to do everything, but I want to have it work without page refresh. Typically I would do this all in PHP, and if there is no such email entry in my database, it would respond back after a page refresh. The thing is, I want the file that this page is using as a POST to be able to send back data to the page without a refresh, showing an error or not.

I'm going to be using jQuery $.post(). Any help?

Here's my jQuery post code:

 $.post('php/recoverPost.php', $('#recoverPost').serialize(), function(){
                $('#recoverPost').hide();
                $('#success').show();
            });
  • 写回答

2条回答 默认 最新

  • doomm4711 2011-03-26 19:23
    关注

    You could do something like this:

    $('#registerform').submit(function() {
        e.preventDefault();
        $.ajax({
            'url': 'posturl.php',
            'type': 'POST',
            'data': {
                'email': $('#email').val(),
                'username': $('#username').val()
            },
            'success':function(data) {
                if(data == 'success') {
                    alert('did it!');
                } else {
                    alert('I failed!');
                }
             }
        });
    });
    

    if you make posturl.php echo 'success' if the e-mail doesn't exist this will work.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题