【发布时间】:2014-01-02 23:08:25
【问题描述】:
我有一个简单的 cfc 查询数据库并返回 JSON 对象
<cfcomponent>
<cfsetting showdebugoutput="false" enablecfoutputonly="true">
<cffunction name="getNew" access="remote" returntype="query" returnFormat="json" secureJSON="false">
<cfquery datasource="#request.datasource#" name="qSelectNotes">
SELECT TOP 3 university_ID, name FROM university
</cfquery>
<cfreturn qSelectNotes>
</cffunction>
CFC 正在返回在 FireBug 中查看的以下 JSON:
{"COLUMNS":["UNIVERSITY_ID","NAME"],"DATA":[[1,"MIT"],[2,"EMORY"],[3,"UNC"]]}
我的 jQuery 函数不断返回错误
"SyntaxError: JSON.parse: unexpected character".
我的功能如下:
$.ajax({
url: "notes_DB_check.cfc?method=getNew",
dataType: "json",
success: function (myData) {
alert(myData.DATA[1][1]);
},
error: function (request, status, error) {
alert("REQUEST:\t" + request + "\nSTATUS:\t" + status + "\nERROR:\t" + error);
}
});
【问题讨论】:
-
真的没有“ColdFusion JSON”这样的东西,只有“JSON”。您在此处发布的 JSON 是完全有效的(我确定您已经检查过了),所以无论 是 是否让您的 jquery 代码窒息都不是 那个 JSON。
-
这是一个有用的评论。我一直被锁定在这个,我不认为它可能是其他干扰。我在页面上有另一个 jQuery 函数干扰了这个函数。一旦我删除了这个功能,这个功能就像一个魅力!谢谢!!!
-
酷! :-) 您应该将其总结为答案并标记已回答的问题。如果他们不阅读这些 cmets,它将节省人们尝试提供帮助的时间。
标签: jquery json coldfusion