gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 23:05:02 25 4
gpt4 key购买 nike

我正在使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com