Jquery 如何使用json填充jqGrid表
我正在从json字符串“”创建jqgrid 我编写的JavaScript类似于“”和url 指向john.txt文件 它给了我一张没有任何行的桌子。请帮忙Jquery 如何使用json填充jqGrid表,jquery,json,jqgrid,Jquery,Json,Jqgrid,我正在从json字符串“”创建jqgrid 我编写的JavaScript类似于“”和url 指向john.txt文件 它给了我一张没有任何行的桌子。请帮忙 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <he
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Demonstration how to read simple JSON text</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/themes/redmond/jquery-ui.css" />
<link rel="stylesheet" type="text/css" href="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-3.8.2/css/ui.jqgrid.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.1.min.js"></script>
<script type="text/javascript" src="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-3.8.2/js/i18n/grid.locale-en.js"></script>
<script type="text/javascript" src="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-3.8.2/js/jquery.jqGrid.min.js"></script>
<script type="text/javascript">
//<![CDATA[
jQuery(document).ready(function () {
$('#jqgrid').jqGrid({
url: 'http://www.ok-soft-gmbh.com/jqGrid/John.txt',
datatype: 'json',
colNames: ['Col1', 'Col2', 'Col3'],
colModel: [
{ name: 'col1' },
{ name: 'col2' },
{ name: 'col3' }
],
jsonReader: { repeatitems: false },
height: 'auto'
});
});
//]]>
</script>
</head>
<body>
<table id="jqgrid"><tr><td/></tr></table>
</body>
</html>
演示如何读取简单的JSON文本
//
这就是我的代码…这就是我得到的
首先,您应该小心使用表单中的
url
因为限制。只能对来自同一网站的数据使用ajax请求。因此,为了防止出现这种情况,您应该使用不带协议、域和端口前缀的url。这里,由于您试图访问的数据来自另一个域,因此无法将其直接传递到url
参数。解决方案是,您必须使用自己的json数据进行分配,或者使用自己的域url从中获取数据。或者您可以使用json数据设置一个局部变量,并将其分配给jqGrid我认为这是因为,您正在对另一个域中的资源发出ajax请求
尝试此操作,将下面给定的数据保存到一个文件John.txt中,并将您的URL更改为指向此点
url:'John.txt'
{
"total": 2,
"page": 1,
"records": 12,
"rows": [
{
"id": "1",
"col1": "cell11",
"col2": "cell12",
"col3": "cell13"
},
{
"id": "2",
"col1": "cell21",
"col2": "cell22",
"col3": "cell23"
}
]
}
你应该公布你的确切密码。作品因此,要理解你的问题,你应该知道你的代码。请找到我尝试的代码谢谢。。很抱歉,我的评论太晚了。。其bcs json位于不同的域中。当我把它们放在同一个域中时,它起作用了。