【发布时间】:2018-08-03 09:50:03
【问题描述】:
我有一个非常简单的 Ajax 请求。它只是从数据库中请求一些数据。问题是我总是收到 JSON.parse 错误(第一行,第一列)。 Coldfusion 函数输出的 JSON 有效且正确。
当我将代码复制到 .cfc 文件时,一切正常。这是为什么呢?
冷融合:
<cffunction name="getAllDatatypes" access="remote" returntype="query" returnformat="json">
<cfquery name="getAllDatatypes" datasource="#DSN#">
SELECT
id_datatype,
name
FROM
datatype
</cfquery>
<cfreturn getAllDatatypes>
</cffunction>
jQuery:
function getAllDatatypes() {
$.ajax({
url: "getData.cfm",
type: "post",
dataType: "json",
data: {method: "getAllDatatypes"}
}).done(function(result) {
console.log(result);
}).fail(function(error1, error2, error3) {
console.log(error1 + " " + error2 + " " + error3);
});
}
【问题讨论】:
标签: jquery json ajax coldfusion