【发布时间】:2011-09-06 16:20:28
【问题描述】:
我是 jQuery 新手,我正在尝试创建一个登录页面,该页面将对 CFC 进行 Ajax 调用,该调用在登录是否成功时仅返回 true 或 false。我的电话是用我的论点正确地向 CFC 发出请求,但返回的是问题所在。如果我在 jQuery 中将我的数据类型设置为“html”,我会看到看起来像我在 html 中的整个页面的副本以及我正在寻找的“真实”值。但是,如果我尝试将其设置为“json”,则不会发生任何事情。我正在使用 ColdFusion 9、jQuery 1.6.2。
我的 jQuery 函数:
$(function() {
$('.error').hide();
$(".button").click(function() {
// validate form here
$('.error').hide();
var name = $("input#username").val();
var pass = $("input#password").val();
if (name == "") {
$("label#username_error").show();
$("input#username").focus();
return false;
}
else if (pass == "") {
$("label#password_error").show();
$("input#password").focus();
return false;
}
else {
var bodyContent = $.ajax({
url: "cfc/Login.cfc?method=tryLogin&returnFormat=JSON",
global: false,
type: "POST",
data: {username:name,password:pass},
dataType: "json",
async:false,
success: function(msg){
alert(msg);
}
}
).responseText;
}
});
});
我的 CFC 代码,非常简单,我现在只是想让它正确返回:
<cfcomponent name="Login" output="false">
<cffunction name="tryLogin" access="remote" output="false">
<cfargument name="username" type="string" required="true"/>
<cfargument name="password" type="string" required="true"/>
<cfset var result = true />
<cfreturn result />
</cffunction>
</cfcomponent>
【问题讨论】:
-
你说“什么都没发生”是什么意思?请求是否提出?你能在 Firebug 或任何其他 HTTP 监视工具中看到它吗?是否返回响应?是空的吗?
-
在 Application.cfc 中,您是否将 this.secureJSON 设置为 true 或 false?如果为 true,则将其设置为 false。
标签: jquery coldfusion cfc