如何将值从HTML传递到PHP并使用Include显示它

时间:2017-10-10 07:06:07

标签: php jquery html

我有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文件称为包含在表中

<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
                })
            });
        }
    });
});

1 个答案:

答案 0 :(得分:0)

关于ajax的成功

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