Php 试图将数据从mysql加载到jsgrid
我刚刚开始学习ajax 在这里,我试图在Php 试图将数据从mysql加载到jsgrid,php,jquery,json,ajax,jsgrid,Php,Jquery,Json,Ajax,Jsgrid,我刚刚开始学习ajax 在这里,我试图在jsgrid中从mysql的一个简单表(name details(name,age))加载数据 我在同一个文件夹中有两个文件1)index.php2)hello.php index.php: <Doctype! HTML></Doctype!> <html> <head> <link type="text/css" rel="stylesheet" href="css/jsgri
jsgrid
中从mysql的一个简单表(name details(name,age))加载数据
我在同一个文件夹中有两个文件1)index.php
2)hello.php
index.php
:
<Doctype! HTML></Doctype!>
<html>
<head>
<link type="text/css" rel="stylesheet" href="css/jsgrid.min.css" />
<link type="text/css" rel="stylesheet" href="css/jsgrid-theme.min.css" />
</head>
<body>
<div id="jsGrid"></div>
<script src="js/jquery-3.1.1.min.js"></script>
<script src="js/jsgrid.min.js"></script>
<script src="js/main.js"></script>
</body>
</html>
main.js
$(document).ready(function(){
$("#jsGrid").jsGrid({
width: "70%",
height: "400px",
inserting: true,
editing: true,
sorting: true,
paging: true,
filtering:true,
controller: {
loadData: function(filter) {
return $.ajax({
type: "GET",
url: "hello.php",
data: filter
});
}
},
fields: [
{ name: "name", title: "Name", type: "text", width: 150 },
{ name: "age", title: "Age", type: "number", width: 50, filtering: false },
{ type: "control" }
]
});
});
hello.php
显示了来自数据库的完美数据输出,但是在index.php
中,没有数据加载到jsgrid
中,它显示未找到
请帮忙。
提前谢谢。您能给出一个
hello.php
的输出示例吗,从第一个字符开始,应该是[
[{“name”:“sdff”,“age”:10}]在加载数据
函数中,在数据之后添加:filter,success:function(result){console.log(result);}
。然后在您的(Chrome)中在浏览器中,按F12键并单击Console选项卡。是否看到展开后提供数组[1]的[Object]
…?不,我没有看到类似的内容。在检查“保留日志”时,我只看到导航到:,这是指向我的索引文件的路径。我尝试使用$。获取并在警报中对输出进行字符串化,结果显示正确,只是jsgrid没有使用json编码。您可以尝试在jsgrid外部调用数据库并将其保存在variabl上吗然后调用变量,例如:jsondata=$.post('yourfile.php').done(function(data){var dd=JSON.parse(data)},“JSON”);我将在本周尝试,我会告诉你结果
$(document).ready(function(){
$("#jsGrid").jsGrid({
width: "70%",
height: "400px",
inserting: true,
editing: true,
sorting: true,
paging: true,
filtering:true,
controller: {
loadData: function(filter) {
return $.ajax({
type: "GET",
url: "hello.php",
data: filter
});
}
},
fields: [
{ name: "name", title: "Name", type: "text", width: 150 },
{ name: "age", title: "Age", type: "number", width: 50, filtering: false },
{ type: "control" }
]
});
});