开发者

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 + ')'); 开发者_StackOverflow

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


You forgetting a

+

Should be:

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


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.

},


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜