1

I have 3 HTML Elements

<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>

and a 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);
?>

Now I call this php file in 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>

Now here is my question.

How can I pass those element value in the qry_vsr.php without refreshing or going to blank page and populate data in this php include inside the table?

here is the 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
                })
            });
        }
    });
});
13
  • Try ajax it will help you. Commented Oct 10, 2017 at 7:07
  • hi sir @ShadowFiend please see the edited post Commented Oct 10, 2017 at 7:08
  • @paulpagente i didn;t see any changes in your post.. Commented Oct 10, 2017 at 7:09
  • what a hint? proudly pinoy hahaha here is the link of your help stackoverflow.com/questions/46518784/… Commented Oct 10, 2017 at 7:11
  • Possible duplicate of Passing PHP variable to Jquery without refresh Commented Oct 10, 2017 at 7:11

1 Answer 1

0

on ajax success

$('#tblreport').load('../../php/pages/sfa/qry_vsr.php');
Sign up to request clarification or add additional context in comments.

5 Comments

undefined index on my variables sir
Your data also doesnt need ()'s. use { only.
Yes sir. I try to put sample parameter and it works right
after removing the ()'s from data do you still get it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.