[Answered ]-How to edit the response sent back to jquery after successful form submit in Django

0👍

This view needs to be reached from a normal submit and from an ajax one

1) Add a parameter to the called url for let understand the view if is an ajax call or not, you can also use an hidden field set ad “ajax”

2) If the view found the parameter “ajax” it give you back a message or an error if there is one, otherwise it perform the redirect.

Consider also to use two different urls for the same view

book/create/(?P<type>[a-z])/

book/create/standard/$ """do redirect after submit"""
book/create/ajax/$ """return httpresponse"""

2👍

Add a success parameter to the plugin call:

$('#your_form').ajaxForm({
  success: function(response){
    alert("Data added successfully");
  }
});

Hope this helps. Cheers

Leave a comment