【问题标题】:Ajax submit form doesn't work in online modeAjax 提交表单在在线模式下不起作用
【发布时间】:2017-03-04 16:59:59
【问题描述】:

此代码不能在“在线”模式下工作,但在“本地主机”下工作......有人可以帮助我吗?控制台不显示错误。

function contactForm() {
  $.ajax({
    type: 'POST',
    url: 'main.php',
    data: {
      name: $(".js-contact-name").text(),
      email: $(".js-contact-email").text().replace(/(\r\n|\n|\r)/gm, "").replace(/\s+/g, " "),
      subject: $(".js-contact-subject").text(),
      message: $(".js-contact-brief").text().replace(/(\r\n|\n|\r)/gm, "").replace(/\s+/g, " ")},
      success: function (responseText) {                
        $(".js-mail-message").addClass("js-hidden");
        $(".js-contact-submit").addClass("js-hidden");
        $(".js-mail-success").removeClass("js-hidden")
        console.log(responseText);
      },
      async: true
    });
    return false;
  })
}

【问题讨论】:

  • 我也试过 async: false
  • 进入检查元素中的网络选项卡并查看请求的 url 和状态
  • 504,Connectionkeep-aliveContent-Typetext/htmlDateSat,2017 年 3 月 4 日 17:11:37 GMTKeep-Alivetimeout=15ServernginxTransfer-Encodingchunked
  • 你可以试试/main.php
  • 你可以尝试在 ajax 请求的 url 中使用 '/main.php' 或 './main.php'

标签: jquery html ajax forms submit


【解决方案1】:

根据这段代码所属项目的托管服务商,服务器配置不支持请求,ajax。

【讨论】:

    猜你喜欢
    • 2011-11-18
    • 1970-01-01
    • 1970-01-01
    • 2011-02-12
    • 2015-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多