views:

58

answers:

3

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
tag, which is the last tag in the string from my php file.

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:

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.

A: 

JSLint can help you find the problem. Paste in your result and see what it tells you.

Diodeus
A: 

Don't use the getJSON function; use $.get function instead. It has the same interface. Essentially, getJSON is trying to parse your function, which you don't need to do since it's JSONp.

All the best

mattbasta
A: 

You're missing a brace after eval(json.data);

Use this:

jQuery.jSon = {
    getjSon : function () {
        $.getJSON('http://host6.spellnet.net/links/list.php?jsoncallback=?', function(json){eval(json.data);});
 }
}
Gary Willoughby