Derzeit sende ich die Daten über Code auf diese Weise und es funktioniert, aber wie kann ich das gesamte Formular in JSON senden?Wie json serialize Daten von einem Formular zu Ajax mit Django senden
Code:
$.ajax({
url : window.location.href, // the endpoint,commonly same url
type : "POST", // http method
data : { csrfmiddlewaretoken : csrftoken,
email : email,
password : password,
username : username,
dob : dob,
}, // data sent with the post request
Ich will alles senden und abrufen csrfmiddlewaretoken mit Formulardaten json einschließlich.
Ich habe etwas Ähnliches wie das versucht:
var formData = new FormData($('#my_form');
formData.append('csrfmiddlewaretoken', '{{ csrf_token }}');
$.ajax({
url : window.location.href, // the endpoint,commonly same url
type : "POST", // http method
data : formData, // data sent with the post request
Aber dies aus irgendeinem Grund nicht funktioniert. Wie kann ich es zur Arbeit bringen?