<input type="submit" />
will submit the form (and update the page) if you click it by default. So, if you want to prevent it from going to another page, just use another type of button: <input type="button" />
or <button />
or prevent the default event with e.preventDefault()
implemented in jQuery:
$("#subdel").click( function(e) {
$.post( $("#deleteform").attr("action"), $("#deleteform").serializeArray(), function(info){alert(info); document.location.reload(true); });
e.preventDefault();
});
UPDATE: And I've just noticed that you use same IDs for HTML elements inside of a PHP loop. It means that you will have multiple elements having the same ID. It's very wrong. That's why it's not working. When there are multiple same-ID elements, jQuery will select only the first one! So your event handlers will work with only the first form. You may test a very simple example here: http://jsfiddle.net/AEm8B/
To make things work you may use classes instead of IDs. I will place here an example of your form refactored, but IDs should be changed to classes in the whole loop, because it semantically wrong: IDs should be unique.
<FORM class='deleteform' action='delete.php' method='post'>
<INPUT type='hidden' class='mapid' value='<?php echo( $row[0]); ?>'>
<INPUT type='hidden' class='userid' value='<?php echo( $row[2]); ?>'>
<INPUT type='hidden' class='aktuuserid' value='<?php echo( $userID); ?>'>
<INPUT class='subdel' type='submit' OnClick="return confirm('Löschen.Bist Du sicher?');" value='Löschen'>
</FORM>
And your jQuery code:
$(".subdel").click( function() {
var $form = $(this).parents(".deleteForm");
$.post( $form.attr("action"), $form.serializeArray(), function(info){alert(info); document.location.reload(true); });
});
// If you want use this construction instead of e.preventDefault()
// it's better bind it outside of click handler if you're not going
// to submit it with traditional means.
$(".deleteform").submit( function() {
return false;
});*/
or with e.preventDefault (could be more preferable):
$(".subdel").click( function(e) {
var $form = $(this).parents(".deleteForm");
e.preventDefault();
$.post( $form.attr("action"), $form.serializeArray(), function(info){alert(info); document.location.reload(true); });
});
This should make it finally