Jquery rails的跨平台ajax post请求

Jquery rails的跨平台ajax post请求,jquery,ajax,Jquery,Ajax,我无法找到使用jquery的ajax post请求的正确代码。有人能帮我吗。我以前使用过的代码是: $(document).ready(function () { $('#submit-button').click(function() { $.ajax({ type: "POST", url: "http://localhost:3000/batches.json",

我无法找到使用jquery的ajax post请求的正确代码。有人能帮我吗。我以前使用过的代码是:

$(document).ready(function () {
        $('#submit-button').click(function() {
            $.ajax({
                type: "POST",
                url: "http://localhost:3000/batches.json",
                beforeSend: function(xhr) {xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'))},
                xhrFields: {
                    withCredentials: true
                },
                data: {     
                    batch: {
                      name: $("#name").val(),
                      course_id: $("#course_id").val(),
                      start_date: $("#start_date").val(),
                      end_date: $("#end_date").val(),
                      batch_status: $("#batch_status").val(),
                      }
                },
                error: function(data){
                    console.log(data);
                },
                success: function(data) {
                     console.log(data);
                     return false;
                },
            })
        });
    })

你的问题到底是什么?问题是,当我删除xhrFields参数时,它工作正常,并以正确的格式显示所有错误,但当我保存日期时,未经授权访问后端(rails)。但当我不删除它时,数据会被保存,rails日志中的状态是200,但在浏览器控制台日志中它是不同的,这是为什么。。。我的jquery有什么问题吗。。。