dongre1907 2013-04-11 11:41
浏览 25
已采纳

JavaScript验证后PHP函数无效[关闭]

I used validation for my login field with jQuery & Javascript, and it works. When there is no username or password the span text changes.

When the details are correct and I press login it just reloads the page again, instead of starting the session etc.

But if I enter a valid username with a wrong password, PHP kicks in and displays incorrect password or if I enter an invalid username, it says username not found.

This is such a weird problem. I have a feeling it's due to the fact I am returning a flag to check sending, after the Javascript validation:

$(document).ready(function() { 
    $('#loginf').submit(function(){ 
        var flag = true

        //stuff to validate each field 
        //ie: for each field i have:

       if(//empty field) { 
        //stuff flag= false; 
       } 
       return flag; 
   }); 

});
  • 写回答

2条回答 默认 最新

  • douting1871 2013-04-11 11:54
    关注

    If you don't want your page to reload, you should always have

    return false;
    

    in the end of your validation/submit code in JS.

    Otherwise, it will always the default action for the button, in this case, follow the action of the form.

    Are you starting the session in PHP? If you are doing this by AJAX, try checking what data parameters are you sending and receiving with Firebug.

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

报告相同问题?

悬赏问题

  • ¥100 我想找人帮我写Python 的股票分析代码,有意请加mathtao
  • ¥20 Vite 打包的 Vue3 组件库,图标无法显示
  • ¥15 php 同步电商平台多个店铺增量订单和订单状态
  • ¥15 关于logstash转发日志时发生的部分内容丢失问题
  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现