简体   繁体   English

jQuery ajax post()请求未与XHR标头一起发送

[英]jquery ajax post() request not sent with XHR header

The following is the javascript from my erb template. 以下是我的erb模板中的javascript。 When the user submits the form, it should be hijacked by jquery, the data submitted via a $.post(), and return false should prevent the page from redirecting, and the form submitting in the traditional manner. 当用户提交表单时,它应该被jquery劫持,通过$ .post()提交的数据,并返回false应该防止页面重定向,并且表单以传统方式提交。 But im still getting the redirect, and request.xhr? 但即时通讯仍在获取重定向,以及request.xhr? is returning false. 返回假。

<% javascript_tag do %>
  jQuery(document).ready(function($){

    action = $('.edit_profile').attr('action');

    $('.edit_profile').submit(function(){

      form_data = $('.edit_profile').serialize();

      $.post(action, function($('.edit_profile').serialize()){
        $.colorbox.close();
      });
      return false;
    })
  });
<% end %>

Try this, there were a few problems with your script. 试试这个,您的脚本有一些问题。

$(function(){
    $('.edit_profile').submit(function(){
        var form_data = $('.edit_profile').serialize();
        $.post(this.action, form_data, function(){
            $.colorbox.close();
        });
        return false;
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM