我找不到使用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;
},
})
});
})