0

I'm trying to submit a form without refreshing the page and so I used ajax. It gets the job done but my problem is that it refreshes the page. I want to prevent it from refreshing the page. Any help?

Code below:

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script>
$(function() {
  $("#deleteimages").click(function(e) {
    e.preventDefault();
    $.ajax({
      type: 'POST',
      url: 'includes/do.php',
      data: $(this).serialize(),
      success: function(alert) {
        alert(alert);
      }
    });
  });
});
</script>

My submit button:

<input type="submit" name="deleteimages" id="deleteimages" value="DELETE">

Any help please? Thank you!

mplungjan
  • 169,008
  • 28
  • 173
  • 236
Mub
  • 13
  • 4
  • @piotrbienias duplicate? this is my first post here. – Mub Mar 01 '17 at 14:43
  • This meens someones already asked for a similar issue... Anyway, try to replace your submit input by a simple button. This will not trigger the form submission. – Sir McPotato Mar 01 '17 at 14:44
  • By duplicate I mean that similar or the same question was already asked on StackOverflow so there is no need to ask it again - just look for the answer – piotrbienias Mar 01 '17 at 14:44
  • @piotrbienias I did. but i didn't get any answers. I have two submit buttons and i want to trigger the ajax only on one of them. Thats why i did not use $('form').on('submit', function (e) – Mub Mar 01 '17 at 14:46
  • @SirMcPotato I didnt find a solution – Mub Mar 01 '17 at 14:46
  • Change type="submit" to type="button" – mplungjan Mar 01 '17 at 14:59

0 Answers0