【问题标题】:prevent redirection on submit to form防止提交到表单时重定向
【发布时间】:2012-10-30 00:57:55
【问题描述】:

我使用以下代码将表单提交到处理脚本。表单被提交,但我被重定向到来自服务器的响应 html。我想留在同一页面上并在成功内运行回调函数:

响应头正在发送 位置:http://url-I-am-Redirected-to-and-don't-want-to-be.html

我正在与第三方合作,无法控制我提交的服务器端代码。

  $('#go').click (function () {

        $.ajax ( {
        type: 'POST',   
        data: $('#newsletter form').serialize(),
        url: $('#newsletter').attr('action'),
        success: function(){
        $('#image_container').hide (1000,

       );
      }
     });

    }

【问题讨论】:

  • 您是否在代码 sn-p 的末尾缺少尾随 ')'?
  • 此外,隐藏调用缺少结束括号,结束 ajax 块的括号和卷曲混淆了。

标签: ajax post


【解决方案1】:

在点击块末尾添加

return false

【讨论】:

  • @Daedalus 我的额外的 cmets 你满意吗?
  • 这不是为了取悦我,而是为了帮助 OP,但确实如此。
猜你喜欢
  • 2011-08-20
  • 2017-05-05
  • 2011-05-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-18
  • 2017-09-15
  • 2017-07-29
相关资源
最近更新 更多