【问题标题】:Classic ASP + Ajax Form - success function not working, complete is ok经典 ASP + Ajax 表单 - 成功功能不起作用,完成即可
【发布时间】:2016-08-03 02:40:02
【问题描述】:

使用 Ajax 和 JS/Jquery 我正在尝试将简单的联系表单发送到经典 ASP (aspemail) 并从页面发送消息无需重新加载

  <form id="form-submit" action="ASPEmail.asp" method="post">
    Name<br>
    <input id="name" type="text"><br>
    E-mail<br>
    <input id="email" type="text"><br>
    Message:<br>
    <textarea id="msg"></textarea><br>
    <input type="submit" id="btn" value="SEND">
    <img src="loading.gif" class="loading">
   </form>

我的 ASPEMAIL.ASP 只是测试 asp,我只写:

<% 
Response.Write("ok")
%>

还有我的 JQuery 脚本:

<script   src="https://code.jquery.com/jquery-3.1.0.js"></script>

<script>
$(function() {

   $("#form-submit").submit(function() {
      var data = $(this).serialize(),
          action = $(this).attr("action"),
          method = $(this).attr("method");

      $(".loading").show(); // show loading div
      $.ajax({
         url: action,
         type: method,
         data: data,
         success: function(data) {

            if(data === "ok")
            {
             document.location = "final.asp";
            }

         },
         error: function(err) {
             // there was something not right...
         },
         complete: function() {
            $(".loading").hide(); // hide the loading
         }
      });

      return false; // don't let the form be submitted
   });

});
</script>

我对成功进行了重定向以进行测试(我的目标只是一条消息)-但没有任何反应。

但发送后“加载”出现在屏幕上并隐藏,然后提交和“完成”工作。

知道有什么问题吗?

【问题讨论】:

  • data 在控制台登录时返回什么? (在succes: function(data) {}if 函数之前?
  • Check the browser console 看看到底发生了什么;特别是网络标签。

标签: javascript jquery ajax asp-classic


【解决方案1】:

您有 2 个名为 data 的变量,请尝试在此处使用不同的变量,因为我相信您在这里“混淆”了 javascript :)

 success: function(dataReturned) {

            if(dataReturned === "ok")
            {
             document.location = "final.asp";
            }

         },

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多