[英]Why am I getting a syntax error after my Json result?
I'm using Json to retrieve data from a database, construct some html, and put it to the page, but I'm getting a syntax error after my 我正在使用Json从数据库中检索数据,构造一些html并将其放到页面上,但是我收到我的语法错误
tag, which is the last tag in the string from my php file. 标签,这是我的php文件中字符串中的最后一个标签。
PHP: PHP:
if($QString == "")
{
$query = "SELECT * FROM categories";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$categories="<a href=" . '"' . "?catID=" . $row['catID'] . '"' . ">" . $row['CatName'] . "</a><br>";
echo $_GET['jsoncallback'] . $categories;
}
}
jQuery: jQuery的:
var jSon = {};
$(function(){
jQuery.jSon.getjSon();
});
jQuery.jSon = {
getjSon : function () {
$.getJSON('http://host6.spellnet.net/links/list.php?jsoncallback=?', function(json) {
eval(json.data);
});
}
Any Help would be greatly appreciated. 任何帮助将不胜感激。 I'm getting closer and closer. 我越来越近了。
You're missing a brace after eval(json.data);
您在eval(json.data);
之后缺少大括号eval(json.data);
Use this: 用这个:
jQuery.jSon = {
getjSon : function () {
$.getJSON('http://host6.spellnet.net/links/list.php?jsoncallback=?', function(json){eval(json.data);});
}
}
Don't use the getJSON
function; 不要使用getJSON
函数; use $.get
function instead. 使用$.get
函数代替。 It has the same interface. 它具有相同的界面。 Essentially, getJSON
is trying to parse your function, which you don't need to do since it's JSONp. 本质上, getJSON
试图解析您的函数,因为它是JSONp,所以您不需要这样做。
All the best 祝一切顺利
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.