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 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口