Javascript 用php提交html表单

Javascript 用php提交html表单,javascript,php,html,Javascript,Php,Html,这是我的第一个.php页面html部分。我有一个表单,包括一个div和一个submit按钮。我希望在单击按钮时,打开一个新页面(second.php)并显示div的内容(id=orderList) <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></s

这是我的第一个.php页面html部分。我有一个表单,包括一个div和一个submit按钮。我希望在单击按钮时,打开一个新页面(second.php)并显示div的内容(id=orderList)

<html>
   <head>    

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="script.js"></script>

    <META name=viewport content="width=1024, initial-scale=1">
    <META http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <META HTTP-EQUIV="Content-language" CONTENT="tr">

    <link href="shift.css" rel="stylesheet">   
    <link rel="stylesheet" href="bootstrap.css">
    <link rel="stylesheet" href="product.css">

 </head>

  <body>

    <div id="confirmForm">  </div> 

  </body>

</html>
这是second.php,我想在这里显示div中的内容(id=confirmForm)

<html>
   <head>    

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="script.js"></script>

    <META name=viewport content="width=1024, initial-scale=1">
    <META http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <META HTTP-EQUIV="Content-language" CONTENT="tr">

    <link href="shift.css" rel="stylesheet">   
    <link rel="stylesheet" href="bootstrap.css">
    <link rel="stylesheet" href="product.css">

 </head>

  <body>

    <div id="confirmForm">  </div> 

  </body>

</html>

如果
$('confirmForm')
不是输入项,您不能使用
$('confirmForm').val()访问它

<html>
   <head>    

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="script.js"></script>

    <META name=viewport content="width=1024, initial-scale=1">
    <META http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <META HTTP-EQUIV="Content-language" CONTENT="tr">

    <link href="shift.css" rel="stylesheet">   
    <link rel="stylesheet" href="bootstrap.css">
    <link rel="stylesheet" href="product.css">

 </head>

  <body>

    <div id="confirmForm">  </div> 

  </body>

</html>
您的表单缺少
method
属性,默认情况下,将
POST
添加到其
GET

<html>
   <head>    

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="script.js"></script>

    <META name=viewport content="width=1024, initial-scale=1">
    <META http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <META HTTP-EQUIV="Content-language" CONTENT="tr">

    <link href="shift.css" rel="stylesheet">   
    <link rel="stylesheet" href="bootstrap.css">
    <link rel="stylesheet" href="product.css">

 </head>

  <body>

    <div id="confirmForm">  </div> 

  </body>

</html>
<form id="orderForm" method="post" action="second.php">
在第二页中,您可以这样做

<html>
   <head>    

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="script.js"></script>

    <META name=viewport content="width=1024, initial-scale=1">
    <META http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <META HTTP-EQUIV="Content-language" CONTENT="tr">

    <link href="shift.css" rel="stylesheet">   
    <link rel="stylesheet" href="bootstrap.css">
    <link rel="stylesheet" href="product.css">

 </head>

  <body>

    <div id="confirmForm">  </div> 

  </body>

</html>
<div id="confirmForm"> <?php echo $_POST['confirmForm'] ?> </div> 

您正在尝试将内容放入#confirmForm中,而第一个文件中没有该格式

<html>
   <head>    

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="script.js"></script>

    <META name=viewport content="width=1024, initial-scale=1">
    <META http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <META HTTP-EQUIV="Content-language" CONTENT="tr">

    <link href="shift.css" rel="stylesheet">   
    <link rel="stylesheet" href="bootstrap.css">
    <link rel="stylesheet" href="product.css">

 </head>

  <body>

    <div id="confirmForm">  </div> 

  </body>

</html>
这里不需要JavaScript。使用$\u['post']获取div的内容

尝试以下操作:

<html>
   <head>    

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="script.js"></script>

    <META name=viewport content="width=1024, initial-scale=1">
    <META http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <META HTTP-EQUIV="Content-language" CONTENT="tr">

    <link href="shift.css" rel="stylesheet">   
    <link rel="stylesheet" href="bootstrap.css">
    <link rel="stylesheet" href="product.css">

 </head>

  <body>

    <div id="confirmForm">  </div> 

  </body>

</html>
first.php

<html>
   <head>    

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="script.js"></script>

    <META name=viewport content="width=1024, initial-scale=1">
    <META http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <META HTTP-EQUIV="Content-language" CONTENT="tr">

    <link href="shift.css" rel="stylesheet">   
    <link rel="stylesheet" href="bootstrap.css">
    <link rel="stylesheet" href="product.css">

 </head>

  <body>

    <div id="confirmForm">  </div> 

  </body>

</html>
<html>
<head>
</head>
<form id="orderForm" action="second.php">
          <div class="col-md-5" id="orderList">
               <textarea name="confirmForm" id="confirmForm" cols="30" rows="10">Sipari Listesi</textarea>
          </div>  
          <div>
               <button type="submit" id="firstConfirmButton" class="btn btn-primary btn-lg">Onayla</button>
          </div>
</form>
</html>
<html>
  <body>

<?php 
  echo $_REQUEST[confirmForm];
?>

  </body>
</html>

李斯特西帕里酒店
奥纳伊拉
second.php

<html>
   <head>    

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="script.js"></script>

    <META name=viewport content="width=1024, initial-scale=1">
    <META http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <META HTTP-EQUIV="Content-language" CONTENT="tr">

    <link href="shift.css" rel="stylesheet">   
    <link rel="stylesheet" href="bootstrap.css">
    <link rel="stylesheet" href="product.css">

 </head>

  <body>

    <div id="confirmForm">  </div> 

  </body>

</html>
<html>
<head>
</head>
<form id="orderForm" action="second.php">
          <div class="col-md-5" id="orderList">
               <textarea name="confirmForm" id="confirmForm" cols="30" rows="10">Sipari Listesi</textarea>
          </div>  
          <div>
               <button type="submit" id="firstConfirmButton" class="btn btn-primary btn-lg">Onayla</button>
          </div>
</form>
</html>
<html>
  <body>

<?php 
  echo $_REQUEST[confirmForm];
?>

  </body>
</html>


除了Saqueib所说的,我认为您还需要对jQuery进行更改。我想您是在寻找html()方法,而不是val(),因为它看起来像是在试图更改显示的html,对吗?

Google
ajax
with
jquery
如果您希望第二个页面的内容显示在当前页面上,您是在使用异步请求提交表单。我应该如何使用$\u['post'],在first.php或second.php中?我更改了它,但仍然为空,我可以看到充满内容的文本区域,没有问题,需要解决。但是second.php是空的吗?var_dump($_POST['confirmForm']);是空的,只需使用
print\r($\u POST)在第二页的顶部,查看它提供了什么。您必须从表单提交中获取内容,然后使用上面我向您展示的键print\r($\u POST);结果是Array()将表单方法更新为post
,这样就可以了。谢谢,我忘了把textarea放在订单上。我试过了,但两次都被拒绝了。但我不知道为什么。
<html>
   <head>    

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="script.js"></script>

    <META name=viewport content="width=1024, initial-scale=1">
    <META http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <META HTTP-EQUIV="Content-language" CONTENT="tr">

    <link href="shift.css" rel="stylesheet">   
    <link rel="stylesheet" href="bootstrap.css">
    <link rel="stylesheet" href="product.css">

 </head>

  <body>

    <div id="confirmForm">  </div> 

  </body>

</html>