dtnat7146 2019-03-13 23:33
浏览 113

html表单中的动作脚本未正确执行

I am trying to learn a bit web development and want to build my own small website with a login screen. The html form looks like this:

<form action="./scripts/login.php" method="post">
    <input type="text" name="username" placeholder="Enter Username" autofocus>
    <input type="password" name="password" placeholder="Enter Password">
    <p>Forgot password?</p>
    <input type="submit" value="Confirm" name="submit_login">
</form>

and the login.php like this:

<?php
alert("Hello World");

function alert($msg) {
    echo "<script type='text/javascript'>alert('$msg');</script>";
}

If I open the website from phpstorm and click on the submit button then I get redirected to the login.php, but the website shows the error 404 not found (even if the path is correct). If I press f5 to reload the website I get the message "To display this page, Firefox must send information that will repeat any action (such as a search or order confirmation) that was performed earlier." with the options to cancel or resend but neither results in the message "Hello World" from the script. If I click on the url in the bar at the top of firefox and then press enter instead of f5 (both should reload the webside), the expected message appears. At least I opened the .html file directly from firefox with the "Open File..." option and if I click on the submit button, the browser ask me if I want to download the login.php file.

I don't why I get these different behaviors and could not find other solutions on the internet. Can anyone help me?

EDIT: If I run the website via xampp no problem occur. But I still don't know why it won't work if I open the website out of xampp.

  • 写回答

1条回答 默认 最新

  • douya7121 2019-03-14 16:28
    关注

    Did you try removing the "." from the /scripts/login/php?

    <form action="/scripts/login.php" method="post">
      <input type="text" name="username" placeholder="Enter Username" autofocus>
      <input type="password" name="password" placeholder="Enter Password">
      <p>Forgot password?</p>
      <input type="submit" value="Confirm" name="submit_login">
    </form>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学中在线排序的时间在线排序的在线LPT算法
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧