I have a multi-step form and I want to save the forms as I proceed further using Ajax and not using the post handler. is it possible, to use a reference code?
Javascript Code
<script>
$("form[name="profile_info_form"]).submit(function(e) {
e.preventDefault();
var csrftoken = jQuery('[name=csrfmiddlewaretoken]').val();
var form = $("#profile_info_form");
$.ajax({
method: form.attr("method"),
url: form.attr("action"),
data: {
csrfmiddlewaretoken: csrftoken,
form: form.serialize()
},
dataType: 'Html',
success: function (data) {
$('.form-container').html(data);
}
});
</script>
Views.py
@login_required
def save_profile_info(request):
if request.method == 'POST':
form = ProfileInfoForm.bind(request=request)
if form.is_valid():
form.save()
return {"status": "success"}
else:
return {"status": "fail"}`
The view here is returning a dict for some reason. This is not valid django. I believe also that this issue is obsolete, given the discussion on the discord.
Hi Guys,
I have a multi-step form and I want to save the forms as I proceed further using Ajax and not using the post handler. is it possible, to use a reference code?
Javascript Code
Views.py
Error:
Regards, Akhilesh