简体   繁体   English

为什么我的Json结果出现了语法错误?

[英]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 祝一切顺利

JSLint can help you find the problem. JSLint可以帮助您发现问题。 Paste in your result and see what it tells you. 贴上您的结果,看看结果如何。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我的网站上出现参考错误和语法错误? - Why am I getting a reference error and syntax error on my site? 为什么我的 if 语句出现语法错误 - Why am i getting a syntax error on my if statement 为什么我在JavaScript中收到语法错误? - Why am I getting a syntax error in JavaScript? 当我尝试从这个 JSON 文件中获取信息时,为什么会出现语法错误? - Why am I getting a syntax error when I try to take info from this JSON file? 为什么在脚本的第一行出现JS错误语法错误:无效或意外的令牌? - Why am I getting the JS error in line one of my script Syntax error: invalid or unexpected token? 为什么我的代码中出现错误 - Why am I getting a error in my code 在数组中遍历JSON对象时,为什么会出现语法错误? 如何正确提取JSON? - Why am I getting a Syntax Error when looping through JSON Objects in an array? How do I extract JSON correctly? 为什么在尝试分页时出现语法错误(JavaScript)? - Why am I getting syntax error (JavaScript) trying to do a pagination? 为什么在 Javascript 中使用“类”时会出现语法错误 - Why am I getting a Syntax error when using “class” in Javascript 为什么我的计算器得到未定义的结果? - Why am I getting an undefined result with my calculator?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM