1

I am having a web page with two drop down menu, Search button and a table, the table is grabbing information on load using jquery. On loading the table grabs information fine. But when I use drop down menus and search button to update this table, it does not work, How ever the information is there in response console. Here is my code

HTML Code

<div id="table"></div>

Jquery for load table

$(document).ready(function(){
    $.ajax({
        url: 'folder/list.php',
        success: function (data) {
            $('#table').html(data);
        },
        error: function(){
            alert('Error: Unable to display');
        }
    });

});

Jquery for search

$(document).on('click', '#cont-search', function(event) {
event.preventDefault();
var cate = $('#cat-search').val();
var city = $('#city-search').val(); //Important 

$.ajax({
        url: 'folder/list.php',
        type: 'post',
        dataType: 'json',
        data: {
                cate:cate,
                city:city,
            },
        success: function (data) {
            $('#table').html(data);
        },
        error: function(){
            alert('Error: Unable to display Search');
        }
    });});

PHP CODE

require_once('abc/Item.php');

$cat = $_POST['cate'];
$city = $_POST['city'];

$ser_cont = $item->search_cont($cat,$city);?><div class="table-responsive">
    <table id="myTable-item" class="table table-bordered table-hover table-striped">
        <thead>
            <tr>
                <th>S.No.</th>
                <th>Category</th>
                <th>R No.</th>
                <th>Name</th>
                <th>City</th>
             </tr>
        </thead>
        <tbody>
            <?php 
            $sno = 1;
            foreach($ser_cont as $c): ?>
                <tr align="center">
                    <td><?= $sno++; ?></td>
                    <td><?= $c['cate']; ?></td>
                    <td><?= $c['registno']; ?></td>
                    <td align="left"><?= $c['name']; ?></td>
                    <td><?= $c['dist']; ?></td>
</tr>
            <?php endforeach; ?>
        </tbody>
    </table>

Ricky
  • 35
  • 1
  • 10

2 Answers2

0

you can try by changing the action method to onchange

$(document).on('change', '#cont-search', function(event) {
// your event
}
0

I Solved the issue as it was not a json return so I just removed

dataType: 'json',

from my code and it worked, Thanks to every one for the comments

Ricky
  • 35
  • 1
  • 10