[Answered ]-Django – How to stay on the same page without refreshing page?

2👍

It’s not trivial, but the basic steps you need are:

  1. Write some javascript to usurp the form submit button click
  2. Call your ajax function which sends data to “checking” view
  3. Write a “checking” view that will check if form data has changed
  4. If data have changed, submit the form
  5. If not, just stay on page

This blog post is a nice walkthrough of the entire process (though targeted towards a different end result, you’ll need to modify the view).

And here are some SO answers that will help with the steps above:

  1. Basically:

    $('#your-form-id').on('submit', function(event){
        event.preventDefault();
        your_ajax_function();
    });
    
  2. Call ajax function on form submit

  3. Gotta do yourself!
  4. Submit form after checking

Leave a comment