views:

184

answers:

3

Update: I tried a version of the script without the "beforeContentUpdate" part, and this script returns the following JSON

{"COLUMNS":["TNAME","TBRIEF","GAMEID","TITLEID","RDATE","GNAME","PABBR","PNAME","RSCORE","RNAME"],
"DATA":[["Dark Void","Ancient gods known as 'The Watchers,' once banished from our world by superhuman Adepts, have returned with a vengeance.",254,54,"January, 19 2010 00:00:00","Action & Adventure","X360","Xbox 360",3.3,"14 Anos"]]}

Using the script that includes "beforeContentUpdate," however, returns nothing. I used Firebug to see the contents of the div generated by the tooltip, and it's blank!

Hello, I'm wondering if anyone can help me with a syntax error in line 14 of this code: The debugger says missing ) in parenthetical on var json = eval('(' + content + ')');

// Tooltips for index.cfm 
$(document).ready(function() 
{
    $('#catalog a[href]').each(function()
    {
        $(this).qtip( {
            content: {
            url: 'components/viewgames.cfc?method=fGameDetails',
            data: { gameID: $(this).attr('href').match(/gameID=([0-9]+)$/)[1] },
            method: 'get'
        },
        api: {
            beforeContentUpdate: function(content) {
            var json = eval('(' + content + ')');
            content = $('<div />').append(
            $('<h1 />', {
                html: json.TNAME
                }));
                return content;
            }
        },
        });
    });
});
+2  A: 

You forgetting a

+

Should be:

var json = eval('(' + content + ')');
The MYYN
I added the "+", but now I get another error on the same line that says "missing ) in parenthetical" -- any ideas?
Mel
further reading: [ExtJS - SyntaxError: missing ) in parenthetical](http://stackoverflow.com/questions/1645068/extjs-syntaxerror-missing-in-parenthetical) ...
The MYYN
quote: The missing parenthetical typically indicates that something in the JSON is wrong. It could be an extra character before/after the string. Use Firebug to examine what you are getting back, and make sure it is clear of any extra characters.
The MYYN
What is "content" at that point? Is it valid JS?
d11wtq
@Mel, you have an extra `,` after the `api : {..}` between that and the next `}`.
Gaby
whatever content is, it must be valid js, this tool might be helpful: [http://www.jsonlint.com/](http://www.jsonlint.com/)
The MYYN
I'm returning the data in JSON format through a coldfusion CFC, and I've updated the question to show what comes back if I omit the "onContentUpdate" snippet. Without it, that JSON comes back. With it, nothing does. Or at least the div contents appear to be blank, and the tooltip does not show at all, as though the AJAX request was never made.
Mel
Thank you all for the help. The JSON validator says the JSON coming back is valid :/ (JSON part has been appended to the question). @Gaby, that comma is there because I will add style after I'm done, and I don't think it's an issue as with or without it the error is still the same.
Mel
+1  A: 

the best for this is www.jslint.com

i'd copied and paste your code and show me this:

Problem at line 21 character 10: Extra comma.

},

Martin
Taking out the comma makes not different unfortunately! IT says "problem at line 14: eval is evil" what sort of error is that?
Mel
A: 

Make sure you JSON has no extra characters, the JSON must be valid. Check how the content returns with a plain alert so nothing will change the string.

Also, consider using parseJSON from jQuery instead of eval. Quote:

var obj = jQuery.parseJSON('{"name":"John"}');
alert( obj.name === "John" );
BrunoLM