-2

I have a modal window that pops up when I want to add a new project to my dashboard. I have gotten it to work with post however, I cannot prevent it from refreshing.

What I want to do is after the project is added to the database, show a success message and close the modal window after few seconds, and not refresh the page (i.e. the parent page of the modal).

How can I accomplish this?

Any help would be appreciated.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • 4
    Would you share your code to help others helping you out? Please read this: https://stackoverflow.com/help/mcve – sɐunıɔןɐqɐp May 10 '18 at 11:12
  • Most likely you're not preventing the default form event. You'll need to share the code that you've attempted for others to help. – Lex May 11 '18 at 01:07

1 Answers1

0

You are probably saving data on form submit which will trigger default reload functionality.

Use Javascript/jQuery to do event.preventDefault on form submit and then pass your data to save function using ajax.

**

UPDATE:

** In your scripts add the following code:

jQuery(document).ready(function($) {
    $('form#modal').on('submit', function(event) {
        event.preventDefault();
        savedata();
    });
});

So your Script will be:

<script>
function savedata() {
    /*
     * Do ajax call here.
    */
}
jQuery(document).ready(function($) {
    $('form#modal').on('submit', function(event) {
        event.preventDefault();
        savedata();
    });
});
</script>
Faham Shaikh
  • 983
  • 2
  • 6
  • 15