Mohamad
Mohamad

Reputation: 35349

Javascript syntax error

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;
            }
        },
        });
    });
});

Upvotes: 0

Views: 2062

Answers (4)

Mohamad
Mohamad

Reputation: 35349

This turned out to be another case where the ColdFusion debugger, when request debugging output is turned on, causes an ajax error. This is one big "gotcha" we need to remember when working with ColdFusion with debugging enabled. It breaks down ajax.

Upvotes: 0

BrunoLM
BrunoLM

Reputation: 100331

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" );

Upvotes: 1

Martin Borthiry
Martin Borthiry

Reputation: 5326

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.

},

Upvotes: 1

miku
miku

Reputation: 188024

You forgetting a

+

Should be:

var json = eval('(' + content + ')');

Upvotes: 2

Related Questions