jQuery Ajax函数说“失败”但仍然发送消息

时间:2012-10-18 06:35:04

标签: jquery coldfusion

我在这里遇到一个问题,我觉得我错过了一些东西,但是我不能把手指放在上面。

我有以下内容:

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中的相应参数中提取值...

问题是,它告诉我,每次调用该函数时,“失败”弹出窗口都会失败...但仍然会正确触发电子邮件。 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

2 个答案:

答案 0 :(得分:1)

像这样做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
});

答案 1 :(得分:0)

你试过这样做....我认为这是调用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
 });