gpt4 book ai didi

jquery - Coldfusion:将 json 从一个 CFM 传递到另一个 CFM?

转载 作者:行者123 更新时间:2023-12-01 03:50:47 26 4
gpt4 key购买 nike

基本上,我从一个 CFM 调用另一个 CFM,它创建一个对象,调用该对象上的多个方法并登录用户;否则它会在屏幕上打印错误。

有没有办法获取 CFM 并将 JSON 对象发送到调用它的文件,而不是打印错误?

这是我的ajax:

// processing the login form using jQuery
$("#loginForm").submit(function(event){
// prevents the form from being submitted, the event is the arg to the function
event.preventDefault();

// stores the data from the form into a variable to be used later
dataString = $("#loginForm").serialize();

// the AJAX request
$.ajax
({
type: "POST",
url: "/helpers/auth/ldap/login_demo.cfm",
data: dataString,
//dataType: "text",
success: function()
{
location.reload();
},
error: function(ErrorMsg)
{
$("#hiddenLoginError").show("fast");
$("#loginForm p").css("margin-bottom","3px");
}
});

});

最佳答案

在您的 CFM 页面上,您可以有 <cfif>检查页面是否是通过 ajax 请求的语句。如果是ajax,则返回一个json对象。

<cfset isAjax = (isDefined('cgi.http_x_requested_with') AND lcase(cgi.http_x_requested_with) EQ 'xmlhttprequest')>
...
<cfif isAjax>
<cfcontent reset="true">{ "result":false, "message": "Login Failure" }<cfabort>
</cfif>

然后您可以测试响应:

dataType: "json",
success: function(rdata) {
alert(rdata.message);
}

关于jquery - Coldfusion:将 json 从一个 CFM 传递到另一个 CFM?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8857802/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com