Я пытаюсь отправить некоторые данные через \appointments
через запрос POST для моей функции handleFormSubmit
. Но по какой-то причине я всегда получаю 400 Bad Request Error
:
Вот мой Appointments.jsx
файл:
import React from 'react';
import Appointment from './Appointment';
import AppointmentForm from './AppointmentForm';
import AppointmentsList from './AppointmentsList';
class Appointments extends React.Component {
constructor(props) {
super(props)
this.state = {
appointments: this.props.appointments,
title: 'Put your event title',
appointment_date: 'When would this happen?'
};
this.handleUserInput = this.handleUserInput.bind(this)
}
handleUserInput(obj_value){
this.setState(obj_value);
}
handleFormSubmit(){
let apppointment = {
title: this.state.title,
appointment_date: this.state.appointment_date
};
$.ajax({
type: "POST",
url: '/appointments',
data: { apppointment },
success: function(data){
console.log(data);
}
});
}
render(){
return(
<div>
<AppointmentForm title={this.state.title}
appointment_date={this.state.appointment_date}
onUserInput={this.handleUserInput}
onFormSubmit={this.handleFormSubmit}
/>
<AppointmentsList appointments={this.props.appointments} />
</div>
)
}
}
export default Appointments;
Я пока не уверен, но думаю, что это как-то связано с этим код:
$.ajax({
type: "POST",
url: '/appointments',
data: { apppointment },
success: function(data){
console.log(data);
}
});
Есть идеи, что мне нужно сделать, чтобы это исправить?