drbhjey445647
drbhjey445647
2012-08-31 06:14

Html Post Method刷新后获取空白页面

已采纳

I am testing Html form using post method and got this odd result: I have two html pages on server apache (already installed php): post.html and target.html, and the code for these page are followings:

post.html (don't worry about the html standard)

    <div style="text-align: center">
       <form method="POST" action="target.html">
          <input type="text" name="testname" value="sometext" />
          <input type="submit" value="submit" />
        </form>
    </div>

and target.html

<html>
  <head>
  </head>
  <body>
    <h1>Target page</h1>
  </body>
</html>

When I entered data to the form on post.html page and hit submit button, I got to the target.html page. When on this page(target.html), I refreshed the page, and what I receive is a blank page. The second time I refreshed, It turned to normal Html page.

I don't know why it returned a blank page the first time I refreshed, I have tried the same approach but with PHP page, and the content of target page (assum name target.php) still remains (not blank like html files above) So, could you explain me about this problem? Thank you.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

4条回答

  • douni1396 douni1396 9年前

    This definitely has something to do with your browser. Same here on a mac using Safari, on some pages after submitting the content, the page seems to freeze, I refresh it, and then it works again.

    Definitely not a code problem, as far as I'm concerned.

    点赞 评论 复制链接分享
  • doudun2212 doudun2212 9年前

    save your form page in php than add the php script in the same page, here try this. remember save in .php.

    <?php $testname = $_Post['testname'];
    echo $testname ?>
    
    
    <div style="text-align: center">
           <form method="POST" action="">
              <input type="text" name="testname" value="sometext" />
              <input type="submit" value="submit" />
            </form>
        </div>
    
    点赞 评论 复制链接分享
  • doucai1901 doucai1901 9年前

    It's because you cannot pass an input from html to html file. Your target.html should be a php file (target.php). and try to put this code on your target.php

    <?php
    var_dump($_POST); //this will show the inputted text and also show the data type and will stop the code execution here. other codes below will not be executed.
    echo $_POST['testname'];
    ?>
    

    Additionally, change target.html to target.php in your form action

    点赞 评论 复制链接分享
  • dongtanghuan1885 dongtanghuan1885 9年前

    First I will start out by correcting your post.html

    <div style="text-align: center;"> <!-- added a ; after center -->
       <form method="POST" action="target.html">
          <input type="text" name="testname" value="sometext" />
          <input type="submit" value="submit" />
        </form>
    </div>
    

    that may not matter but you should end all your styles with ;

    To continue, everything looks fine. maybe something weird happened between refreshes.

    点赞 评论 复制链接分享