jqueryajax函数说;“失败”;但仍然发送消息
我有一个问题,我觉得我错过了什么,但我不能把我的手指 我有以下资料:jqueryajax函数说;“失败”;但仍然发送消息,jquery,coldfusion,Jquery,Coldfusion,我有一个问题,我觉得我错过了什么,但我不能把我的手指 我有以下资料: function success(){ alert("success"); } function failure(){ alert("failure"); } function sendData(){ var userName = $("#contact-name-data").val(); var userPhone = $("#contact-phone-data").val(
function success(){
alert("success");
}
function failure(){
alert("failure");
}
function sendData(){
var userName = $("#contact-name-data").val();
var userPhone = $("#contact-phone-data").val();
var userEmail = $("#contact-email-data").val();
var userQuery = $("#contact-enquiry-data option:selected").text();
var request = $.ajax({
url: "http://my.domain-blahblah.com.au/scripts/touchscreen_email.cfm?name="+encodeURIComponent(userName)+"&phone="+encodeURIComponent(userPhone)+"&email="+encodeURIComponent(userEmail)+"&query="+encodeURIComponent(userQuery), success: success, error: failure});
}
调用时,会触发一个非常简单的CFMAIL命令,从URL中的各个参数中提取值
问题是,它告诉我每次调用函数时都会出现“failure”弹出框,结果失败了。。。但仍然正确地发送电子邮件。ColdFusion是完美的。所以我想我的Ajax一定是在什么地方搞砸了
知道我遗漏了什么吗
服务器端代码:
<cftry>
<cfmail from="touchscreen@my.domain-blahblah.com.au" to="eliseo.dannunzio@my.domain-blahblah.com.au" subject="Touchscreen Data" type="html" spoolenable="yes">
<head>
<style type="text/css">
body {
font-family: 'Calibri';
font-size: 12pt;
}
h3 {
margin: 0px 0px 8px 0px;
padding: 0px 0px 0px 0px;
}
span {
font-weight: bold;
}
</style>
</head>
<body>
<h3>Touchscreen Data</h3>
<p>
<span>Name: </span>#url.name#<br />
<span>Phone: </span>#url.phone#<br />
<span>E-Mail: </span>#url.email#<br />
<span>Request: </span>#url.query#<br />
<span>Timestamp: </span>#DateFormat(Now(), "dd mmm yyyy")# #TimeFormat(Now(), "hh:mm tt")#<br />
</p>
</body>
</cfmail>
<cfcatch type="any">
#cfcatch.Message# - #cfcatch.Detail#
</cfcatch>
</cftry>
Done
身体{
字体系列:“Calibri”;
字号:12号;
}
h3{
保证金:0px 0px 8px 0px;
填充:0px 0px 0px 0px;
}
跨度{
字体大小:粗体;
}
触摸屏数据
名称:#url.Name#
电话:#url.Phone#
电子邮件:#url.email#
请求:#url.query#
时间戳:#日期格式(Now(),“dd-mmm-yyyy”)#时间格式(Now(),“hh:mm-tt”)#
#cfcatch.Message#-#cfcatch.Detail#
多恩
像这样处理ajax请求不是更好吗
var request = $.ajax({
url: "http://my.domain-blahblah.com.au/scripts/touchscreen_email.cfm",
type: "get",
date: { name : encodeURIComponent(userName), phone : encodeURIComponent(userPhone), email : encodeURIComponent(userEmail), query : encodeURIComponent(userQuery)},
success: success,
error: failure
});
你试过这样做吗……我认为这是调用ajax的正确方法
$.ajax({
url: "http://my.domain-blahblah.com.au/scripts/touchscreen_email.cfm",
data:{name:encodeURIComponent(userName),phone:encodeURIComponent(userPhone),email:encodeURIComponent(userEmail),query:encodeURIComponent(userQuery)},
type:'GET',
success: function(msg){ //do something here },
error: failure
});
ajax请求的HTTP状态码是什么?根据函数,一旦我解析出请求对象。。。它将返回状态0和状态文本“error”…请使用firebug或开发工具等工具查看状态代码。只是尝试了一下,并进行了一些小的修复以更正代码。。。(缺少逗号、引号等),它仍然报告失败,但仍然允许通过。。。不知道发生了什么。。。我的意思是Ajax调用有多难,对吧?好吧。。我认为这里不需要ajax。如果我不工作。。。。。。试着用这个<代码>窗口。位置=http://my.domain-blahblah.com.au/scripts/touchscreen_email.cfm?name=“+encodeURIComponent(userName)+”&phone=“+encodeURIComponent(userPhone)+”&email=“+encodeURIComponent(userEmail)+”&query=“+encodeURIComponent(userQuery)“;@bipen,在这种情况下,这是非常重要的,因为我正在运行代码作为我正在构建的应用程序的一部分,并且不想离开当前页面…此应用程序所在的框将无法访问邮件服务器,除非是远程访问。因此,必须使用Ajax将请求发送到执行邮件的远程服务器通过CFMAIL发布。@bipen和DarkRanger刚刚尝试了这个版本,但仍然以“失败”的结果返回"... 这才是真正让我困惑的。。。我正在发送请求。。。这个请求肯定会通过,因为我收到了电子邮件。。。但是,$.ajax调用的响应不正确。。。我们应该继续尝试解决它,还是我应该尝试在服务器端代码中设置CFCATCH来回击遇到的任何问题,而不必担心在客户端报告这些问题?