php - ajax GET 无法使用 jtable 将数据发送到 php 页面

标签 php jquery mysql ajax jquery-jtable

我正在使用 jtable 来显示数据以便于访问。

在这里,我的问题是 php 页面无法获取 $data 值,因此我无法检索查询的数据。 它总是进入 else 案例,不知道为什么!!

我很努力,但没有一个想法是成功的。感谢您的帮助。

HTML:
    <link href="../layout/jtable/jquery-ui.css" rel="stylesheet" type="text/css" />
    <link href="../layout/jtable/themes/metro/blue/jtable.css" rel="stylesheet" type="text/css" />

    <script src="../layout/scripts/jquery-latest.min.js" type="text/javascript"></script>
    <script src="../layout/scripts/jquery-ui.min.js" type="text/javascript"></script>
    <script src="../layout/jtable/jquery.jtable.js" type="text/javascript"></script>


<div align="center">
            <label class="" for="qstring"> <b class="red font-large"> <span class="icon-search"></span> Search &nbsp; </b> </label>
            <input type="text" id="qstring" name="qstring" class="search" style="height:30px; width:40%; font-size:16px" placeholder="Type Name or Department or Mobile" autofocus />
</div> 
<div id="EmployeeContainer"></div>

          <script type="text/javascript">

        $(document).ready(function () {
            $('.search').keyup(function(){
                $.ajax({
                    url: 'EMPActions.php',
                    type: 'get',
                    data: {qstr: $('input#qstring').val()},
                    success: function(response) {
                        $('#EmployeeContainer').jtable('load');
                        //$('#EmployeeContainer').html(response);
                    }
                });
            });

            //Prepare jTable
            $('#EmployeeContainer').jtable({
                title: 'Employee Details',
                actions: {
                    listAction: 'EMPActions.php?action=list'

                },
                fields: {
                    EID: {
                        title: 'EID',
                        width: '10%'
                    },
                    EName: {
                        title: 'EName',
                        width: '20%'
                    },
                    Desgn: {
                        title: 'Designation',
                        width: '10%'                        
                    },
                    Dept: {
                        title: 'Department',
                        width: '15%'
                    },                  
                    Mobile: {
                        title: 'Mobile',
                        width: '15%'                        
                    },
                    EMail1: {
                        title: 'RGUKT Mail',
                        width: '15%'                        
                    },
                    EMail2: {
                        title: 'Other EMail',
                        width: '15%'                        
                    }
                }
            });

        });//

    </script>

PHP Page: EmpActions.php
<?php

    if(isset($_GET['qstr'])){
    $data = '%'.$_GET['qstr'].'%';
    }
    else{
    $data = '%';
    }

try
{   
    //echo $data;

    $table = "employee_data";

    //Open database connection
    //echo $data;
    $con = mysql_connect("localhost","root","xampp123");
    mysql_select_db("ecelldata_2013-14", $con);

      //Getting records (listAction)
      if($_GET["action"] == "list")
      {

        //Get records from database
        $result = mysql_query("SELECT * FROM ".$table." WHERE EName LIKE '$data'");
        //echo $data;
          //Add all records to an array
          $rows = array();
          while($row = mysql_fetch_array($result))
          {
              $rows[] = $row;
          }

          //Return result to jTable
          $jTableResult = array();
          $jTableResult['Result'] = "OK";
          $jTableResult['Records'] = $rows;
          print json_encode($jTableResult);
      }


      //Close database connection
      mysql_close($con);


}
catch(Exception $ex)
{
    //Return error message
    $jTableResult = array();
    $jTableResult['Result'] = "ERROR";
    $jTableResult['Message'] = $ex->getMessage();
    print json_encode($jTableResult);
}

?>

最佳答案

尝试: jquery:

 $.post('EMPActions.php',{

                data = {qstr: $('input#qstring').val()}
                },
                function(response) {
                    $('#EmployeeContainer').jtable('load');
                    //$('#EmployeeContainer').html(response);
                },"json");

PHP

if(isset($_POST['qstr'])){
$data = '%'.$_POST['qstr'].'%';
}
else{
$data = '%';
}

关于php - ajax GET 无法使用 jtable 将数据发送到 php 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22268953/

相关文章:

php - 通过表单将内容输入 MySQL 数据库

javascript - 我想使用 jquery 单击链接后打开回复文本框

php - 我网站的圣诞节和Anouka版本

php - WordPress 和 MySQL 表碎片

javascript - 使用非常大的 Javascript 数组或对象

sql - MySQL - 仅在每个分组值的第一个实例中显示字段值?

PHP 登录应用程序 - 创建新用户时检查用户名是否已存在

javascript - 未捕获的类型错误 : Cannot read property 'children' of undefined

javascript - 下载 HTML 表 colspan 和 rowspan 没有拾取

mysql - Visual Studio 2015 在尝试创建 ADO.NET 实体模型类时仅显示 SQL Server 连接