Javascript 在Php中发布Div内容

Javascript 在Php中发布Div内容,javascript,php,jquery,html,Javascript,Php,Jquery,Html,我有两个php页面。在first.php页面中,用户选择orders,一个div将填充此内容,没有问题。还有一个确认按钮来确认这些列表。当用户单击此按钮时,应该打开second.php页面,并在该页面上显示div的内容。这是我为first.php div和confirm按钮编写的html代码 <form method="post"> <div class="col-md-5" id="orderList"> <h3 ali

我有两个php页面。在first.php页面中,用户选择orders,一个div将填充此内容,没有问题。还有一个确认按钮来确认这些列表。当用户单击此按钮时,应该打开second.php页面,并在该页面上显示div的内容。这是我为first.php div和confirm按钮编写的html代码

 <form method="post">
        <div class="col-md-5" id="orderList">
             <h3 align="centre">Order List</h3>
        </div>  
 </form>                    

 <form role="form" method="post" action="second.php">
        <div id="firstConfirmButton">
             <button type="submit" name="firstConfirmButton" id="firstConfirmButton" class="btn btn-primary btn-lg">Confirm</button>
        </div>
 </form>
php页面有confirForm div,我想显示其中的内容

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

问题出在哪里?

您使用POST方法将表单提交到second.php页面,因此可以使用以下php代码从第二页检索数据:

var_dump($_POST);
因此,基本上,数据存储在$\u POST数组中

关于你的第二个问题。如果首先需要从Javascript获取值,则需要避免提交默认表单。你可以这样做:

$("#firstConfirmButton").click(function(e) {
  var data = $('#orderList').html();
  e.preventDefault();

  //...
}
这将避免“提交”按钮在不向表单中添加所需的POST数据的情况下提交表单。

您的按钮是一个“提交”按钮,因此如果不取消默认事件,表单也将以常规方式提交

您需要捕获事件并取消它:

$("#firstConfirmButton").click(function(e) {
  var content = $('#orderList').html();

  e.preventDefault();

  // the rest of your code
或者在jQuery的现代版本中:

$("#firstConfirmButton").on('click', function(e) {
  var content = $('#orderList').html();

  e.preventDefault();

  // the rest of your code

第二个页面将在适当命名的$u POST数组中包含所有已发布的项目$_POST@user3235456看看我的答案;我看到了array1{[firstconfirbutton]=>string0}当我这样做的时候是的,这是你在表单中设置的firstconfirbutton按钮的值,属性为:name=firstconfirbutton。但是我想要id=orderList的div的值,我该怎么做呢?你的javascript正在提交表单本身,您需要防止默认提交。我会更新我的答案。好吧,我做了,但我不能打开second.php。在更新之后,我把它添加到我的代码中。现在,我可以在.done之后看到警报,但这次我无法打开second.php?@user3235456您应该使用console.log而不是alert,这将为您提供更多信息。在控制台中,您还将看到错误消息,例如,如果脚本路径错误。要获得更多帮助,您需要准确地指定出错的地方。console中没有错误,当我在.done[Log]array1{script.js,第112行[html]中输入console.logdata时,我看到了这一点=>string240 SiparişListesi

1个高脂肪焦糖FrappuccinoSiparişlistesindenıkarmak için tıklayın!

}@user3235456如果进入.done处理程序,您的php脚本已成功执行。如果结果不是您想要的,那么问题就出在php脚本的某个地方。但我需要在second.php中看到这一点。您认为我的second.php或first.php html部分有什么错误?
$("#firstConfirmButton").on('click', function(e) {
  var content = $('#orderList').html();

  e.preventDefault();

  // the rest of your code