weixin_33747129 2014-07-04 15:36 采纳率: 0%
浏览 15

同一页面中的$ _POST链接

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>PHP links</title>
<?php 
echo '<div style="background-color:#ccc; padding:20px">' . $_POST['message'] . '</div>'; 
?>
<style type="text/javascript">
// prepare the form when the DOM is ready 
$(document).ready(function() { 
    // bind form using ajaxForm 
    $('#htmlForm').ajaxForm({ 
        // target identifies the element(s) to update with the server response 
        target: '#htmlExampleTarget', 

        // success identifies the function to invoke when the server response 
        // has been received; here we apply a fade-in effect to the new content 
        success: function() { 
            $('#htmlExampleTarget').fadeIn('slow'); 
        } 
    }); 
});
</style>
</head>

<body>
<form id="htmlForm" action="html-echo.php" method="post"> 
        Display List of Links <input type="text" name="message" value="Hello HTML" /> 
        <input type="submit" value="Submit links" /> 
</form>
</body>
</html>

I am trying to get the results displayed on the same page without having to create a .php page and having the results displayed on a separate page. It's an application where a user can submit any type of link and have the results show up on the page.

Is there a way I could save the results for later reference? Keep the results displayed when the page is refreshed?

  • 写回答

1条回答 默认 最新

  • weixin_33725126 2014-07-05 06:16
    关注
    <!doctype html>
     <html>
      <head>
      <meta charset="UTF-8">
       <title>PHP links</title>
      <?php 
     echo '<div style="background-color:#ccc; padding:20px">' . $_POST['message'] . '</div>'; 
     ?>
     <script type="text/javascript">
        $(document).ready(function() {
                $('#formid form').submit(function(){
                        $.get('result.php', $(this).serialize(), function(data){
                                $('#result').html(data);
    
                        });                             
                        return false;
                });
        });
        </script>
    
     </head>
    
     <body>
      <div id="formid">
      <form> 
        Display List of Links <input type="text" name="message" value="Hello HTML" /> 
        <input type="submit" value="Submit links" /> 
         </form>
         </div>
    
         <div id="result"></div>
         </body>
           </html>
    

    try above format for display the form result on same page without load anotherone php file as new,but you should crerate result.php file for generate the result depend on the form inputs, you can get the values of form by using the $_REQUEST[''] on result.php, below is sample for result.php

    <?php
    
    $message=$_REQUEST['message'];
    
    echo $message;
    

    ?>

    your generated result of the result.php will shows on the index.php <div id="result"></div> without reload or redirect the page

    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探