在div中显示php结果 [英] Displaying php results inside a div

查看:38
本文介绍了在div中显示php结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我详细说明我想要实现的目标.我有3页:index.html,form.html和result.php.当我单击index.html中的按钮时使用jquery,它将在form.html中的index.html中的div中加载.form.html在提交时调用result.php.我想要实现的是,当我单击form.html(在index.html中加载)中的提交按钮时,result.php的结果将显示在加载form.html的index.html中的div中.以下是所有3页的代码.任何帮助都会很棒.

Let me explain in detail what I want to achieve. I have 3 pages: index.html, form.html and result.php. Using jquery when I click a button in index.html it will load form.html inside a div in index.html. form.html on submit calls result.php. What I want to achieve is when I click the submit button in form.html(loaded in index.html), the results from result.php to be displayed in the div from index.html where I loaded form.html. Below is the code for all 3 pages. Any help would be great.

index.html内容:

index.html contents:

<html>
   <head>
       <title>index.html</title>
       <script type="text/javascript" src="/scripts/jquery-1.8.2.min.js"></script>
   </head>
   <body>
   <script type="text/javascript">
   $(document).ready(function () {
   var theme = getTheme();
   $("#loadformbutton").jqxButton({ width: '120', height: '30', theme: theme });
   $("#loadformbutton").bind('click',function()
   {
        $('#div_for_form').load('form.html', function() {});
   });
   });
   </script>
   <div id="buttons">
      <input type="button" value="loadform" id='loadformbutton' />
   </div>
   <div id="div_for_form">
      Here loads form.html
   </div>
   </body>
</html>

form.html的内容:

Contents of form.html:

<html>
   <head>
      <title>form.html</title>
   </head>
   <body>
      <form method="POST" action="result.php">
         <input type="password" name="pass" id="pass"/>
         <input type="submit" value="Ok" id="changepass"/>
      </form>
   </body>
</html>

result.php的内容:

Contents of result.php:

<?php
   $received=$_POST['pass'];
   echo 'Received: '.$received;
?>

此刻它可以正常工作,但是result.php的结果显示在新页面中.

At this moment it is functional but the results from result.php displays in a new page.

推荐答案

$('#changepass').click(function(){
var id = $('input#pass').val();
$.post( 'http://domain.com/result.php' { id : id },
        function(response){
            $('div#div_for_form').html(response);
        });

}); 

这篇关于在div中显示php结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆