我正在使用qTip jQuery插件来生成一个动态工具提示。我的JS中有一个错误,我不确定它的来源是JSON还是JS。工具提示会调用以下函数:(对于所有这些代码,很抱歉,但这是必要的)
<cffunction
name="fGameDetails"
access="remote"
returnType="any"
returnformat="JSON"
output="false"
hint="This grabs game details for the games.cfm page">
<!---Argument, which is the game ID--->
<cfargument
name="gameID"
type="numeric"
required="true"
hint="CFC will look for GameID and retrieve its details">
<!---Local var--->
<cfset var qGameDetails = "">
<!---Database query--->
<cfquery name="qGameDetails" datasource="#REQUEST.datasource#">
SELECT
titles.titleName AS tName,
titles.titleBrief AS tBrief,
games.gameID,
games.titleID,
games.releaseDate AS rDate,
genres.genreName AS gName,
platforms.platformAbbr AS pAbbr,
platforms.platformName AS pName,
creviews.cReviewScore AS rScore,
ratings.ratingName AS rName
FROM
games
Inner Join platforms ON platforms.platformID = games.platformID
Inner Join titles ON titles.titleID = games.titleID
Inner Join genres ON genres.genreID = games.genreID
Inner Join creviews ON games.gameID = creviews.gameID
Inner Join ratings ON ratings.ratingID = games.ratingID
WHERE
(games.gameID = #ARGUMENTS.gameID#);
</cfquery>
<cfreturn qGameDetails>
</cffunction>此函数返回以下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.",
154,
54,
"January, 19 2010 00:00:00",
"Action & Adventure",
"PS3",
"Playstation 3",
3.3,
"14 Anos"
]
]
}我遇到的问题是,每次尝试将JSON附加到layer #目录时,都会得到一个语法错误,显示“缺少括号”。这是我使用的JavaScript:
$(document).ready(function()
{
$('#catalog a[href]').each(function()
{
$(this).qtip( {
content: {
url: '/gamezilla/resources/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;
}
},
style: {
width: 300,
height: 300,
padding: 0,
name: 'light',
tip: {
corner: 'leftMiddle',
size: {
x: 40,
y : 40
}
}
},
position: {
corner: {
target: 'rightMiddle',
tooltip: 'leftMiddle'
}
}
});
});
});你知道我哪里错了吗?几天来,我尝试了很多方法,但都找不到问题所在。
非常感谢!
发布于 2010-11-11 19:41:23
事实证明,是ColdFusion调试器导致了ajax变得非常奇怪。我很久以前就发现了这一点,但直到现在才重新考虑这个问题。当遇到这种性质的错误时,人们应该做的第一件事是关闭CF调试器,以检查它是否导致了问题。
发布于 2010-06-08 02:08:18
在你的javascript的底部有一个额外的括号,在"position“括号关闭之后。
发布于 2010-07-04 08:51:14
对beforeContentUpdate函数的第一行(在eval之前)执行一个console.log(arguments),以确保内容参数是您所期望的?
https://stackoverflow.com/questions/2991638
复制相似问题