prevent redirection on submit to form

放肆的年华 提交于 2020-01-25 08:25:09

问题


I have the following code I am using to submit my form to a processing script. the form gets submitted but I am getting redirected to the response html from the server. I want to stay on the same page and run the callback function inside success:

the response header is sending location:http://url-I-am-Redirected-to-and-don't-want-to-be.html

I am working with third party and have no control over the server side code I am submitting to.

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

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

       );
      }
     });

    }

回答1:


At the end of the click block add

return false


来源:https://stackoverflow.com/questions/13131802/prevent-redirection-on-submit-to-form

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!