【问题标题】:How to pass value from HTML to PHP and display it using Include如何将值从 HTML 传递到 PHP 并使用 Include 显示它
【发布时间】:2017-10-10 07:06:06
【问题描述】:

我有 3 个 HTML 元素

<input id = "startdate" name = "startdate" type="text" class="datepicker form-control" placeholder="Start Date...">
<input id = "enddate" name = "enddate" type="text" class="datepicker form-control" placeholder="End Date...">
<button class="btn btn-block btn-lg btn-primary waves-effect" id="btngenerate" name="btngenerate">Generate FSP Report</button>

还有一个 qry_vsr.php

<?php
require 'conn.php';
$startdate = $_POST['startdate'];
$enddate = $_POST['enddate'];


$sql = 'My Query Here with the parameter'
$result = mysqli_query($con, $sql);

while ($array = mysqli_fetch_row($result)) {
    echo 'Create Table';
}

mysqli_close($con);
?>

现在我把这个 php 文件称为 include in a table

<table id="dtable" name="dtable" class="table table-bordered table-striped table-hover js-basic-example dataTable">
    <thead id="thead" name="thead">
        <tr>
            <th>Table Headers Here</th>
        </tr>
    </thead>
    <tbody id = "tblreport">
        <?php include('../../php/pages/sfa/qry_vsr.php') ?>
    </tbody>
</table>

现在这是我的问题。

如何在qry_vsr.php 中传递这些元素值而不刷新或转到空白页并在此 php 包含表中填充数据?

这里是ajax

$(document).ready(function () {
    $('#btngenerate').click(function (e) {
        var d1 = $('#startdate').val();
        var d2 = $('#enddate').val();
        var fspcode = $('#fspcode').find(":selected").text();
        var count = 0;
        var i;
        var x;


        if (d1 == "" || d2 == "" || fspcode == "Nothing Selected") {
            sfaMsgbox('Please provide proper date range and select FSP.');
        } else if (d2 < d1) {
            sfaMsgbox('Improper date range.');
        } else {
            $.ajax({
                url: '../../php/pages/sfa/qry_vsr.php',
                type: "POST",
                datatype: 'json',
                data: ({
                    startdate: d1,
                    enddate: d2,
                    fsp: fspcode
                })
            });
        }
    });
});

【问题讨论】:

标签: php jquery html


【解决方案1】:

关于ajax成功

$('#tblreport').load('../../php/pages/sfa/qry_vsr.php');

【讨论】:

  • 我的变量上未定义的索引先生
  • 您的数据也不需要 () 的。仅使用 {。
  • 是的,先生。我尝试输入示例参数,它工作正常
  • 从数据中删除 () 后你还能得到它吗?
猜你喜欢
  • 2019-12-23
  • 2017-01-09
  • 2014-11-28
  • 1970-01-01
  • 2014-02-17
  • 2015-08-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多