[英]How can I fix JSON.parse: unexpected character Line 550 jQuery.js error for jTable plugin?
Hi I am using php to connect to my database. 嗨,我正在使用php连接到我的数据库。 Here is my list action code: the table and database do have the same name
这是我的列表操作代码:表和数据库确实具有相同的名称
<?php
try
{
//Open database connection
$con = mysql_connect("localhost","root","");
mysql_select_db("702data", $con);
//Getting records (listAction)
if($_GET["action"] == "list")
{
//Get records from database
$result = mysql_query("SELECT * FROM 702data;");
//Add all records to an array
$rows = array();
while($row = mysql_fetch_assoc($result))
{
$rows[] = $row;
}
//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
$jTableResult['Records'] = $rows;
print json_encode($jTableResult);
}
and here is my jtable initialization: 这是我的jtable初始化:
<body>
<div id="DeviceTableContainer"></div>
<script type="text/javascript">
$(document).ready(function() {
$('#DeviceTableContainer').jtable({
title: 'Wireless Monitor',
actions: {
listAction: 'DeviceActions.php?action=list',
createAction: 'DeviceActions.php?action=create',
updateAction: 'DeviceActions.php?action=update',
deleteAction: 'DeviceActions.php?action=delete'
},
fields: {
DeviceId: {
key: true,
list: false
},
DeviceTag: {
title: 'Device Tag',
width: '40%'
},
PV: {
title: 'PV',
width: '10%'
},
SV: {
title: 'SV',
width: '10%'
},
Timestamp: {
title: 'Timestamp',
width: '30%',
type: 'date',
create: false,
edit: false
}
}
});
$('#DeviceTableContainer').jtable('load');
});
</script>
</body>
The error I am receiving is on this line in jQuery.js: 我收到的错误是在jQuery.js的这一行上:
parseJSON: function( data ) {
// Attempt to parse using the native JSON parser first
if ( window.JSON && window.JSON.parse ) {
return window.JSON.parse( data );////////////////////////////////////
}
It looks like it is parsing the entire deviceactions.php file because in firebug the data object has the entire file net to it as a string. 看起来它正在解析整个deviceactions.php文件,因为在Firebug中,数据对象将整个文件网络作为字符串存储到了网络中。 I am very new to web dev so it could be something obvious.
我是Web开发人员的新手,因此可能很明显。 I am also developing this as a java web application if that matters.
如果重要的话,我也正在将其开发为Java Web应用程序。 Thanks
谢谢
edit: here is some more information about the error 编辑:这是有关该错误的更多信息
parseJSON()jquery.js (line 550)
data = "<?php\r\ntry\r\n{\r\n //Open ...TableResult);\r\n}\r\n \r\n?>"
ajaxConvert()jquery.js (line 8447)
s = Object { url="DeviceActions.php?action=list", type="POST", isLocal=false, more...}
response = "<?php\r\ntry\r\n{\r\n //Open ...TableResult);\r\n}\r\n \r\n?>"
jqXHR = Object { readyState=4, responseText="<?php\r\ntry\r\n{\r\n //Open ...TableResult);\r\n}\r\n \r\n?>", getResponseHeader=function(), more...}
isSuccess = true
返回响应时,确保服务器(PHP)将内容类型标记为JSON
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.