dpp10181 2017-06-07 04:26
浏览 52
已采纳

在将数据发送到PHP脚本之前,Javascript重新加载页面

Background: I want to create a login form, the user input the "user ID" and "password". My JavaScript file checks certain parameters. If the data does not comply with them the my page is re-load. If the data is approved then after checking in JavaScript my PHP script kicks in and does other stuff.

Question: the problem I am having is that even though the data is not complaint with the JavaScript check up my page is not re-loading. It keeps sending the data to my PHP script.

Which is want I do not want.

I want to re-loed the same page and not send to PHP. I want to send the data to PHP when the data has passed the JavaScript check up.

CODE:

HTML SECTION

enter image description here

JavaScript SECTION

enter image description here

Thank you

If you guys can suggest a way to approach this situation it would be great.

Thank you.

  • 写回答

1条回答 默认 最新

  • dongyin2390 2017-06-07 04:32
    关注

    Your approach is incorrect , you don't need to reload the page in case of none valid entries , I would suggest doing something similar to the following :

    function checkForm(){
      if(document.getElementById("whatever").value != 'xyz') {
        console.log("False !")
        return false;
      }
      return true
    }
    <form action="something.php" onsubmit="return checkForm()">
    <input type="text" id="whatever">
    <input type="submit">
    </form>

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题