How to edit the response sent back to jquery after successful form submit in Django
I have this code
(r'^book/create/$', create_update.create_object, book_model)
book_model = {'model' : Book, "template_name" : "app/generic_form.html",}
I also have get_absolute_url(self)
so that after creating new row it gets redirected to
/books/lists
The form is working fine.
Now I have used jquery Form plugin to submit the form. Now when i submit the form then data gets inserted via Ajax but don't get anything back.
I think when forms finishes post then it will redirect or /books/list
so that can be the reason why i don't get any data back to jquery.
Now i want that form should work as it is but when i use jquery then i want to display so开发者_Python百科mething data added succesfuly but i don't know how to do that as i am using generic views
Add a success
parameter to the plugin call:
$('#your_form').ajaxForm({
success: function(response){
alert("Data added successfully");
}
});
Hope this helps. Cheers
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"""
精彩评论