• Administrator
    Welcome to the new PunBB.biz design forum.

    We decide to switch from Forumotion due to technical limitations.

    Information: Choosing social login option will register your account automatically without need for email confirmation.

[JavaScript] Delete message via AJAX (without refreshing the page)

A place for codes and tutorials which will improve the functionality of your board.
Post Reply
User avatar
Posts: 19
Joined: Sat Jan 06, 2018 4:56 pm

Sun Jan 07, 2018 1:15 am

The following code will delete a message using AJAX.


Installation steps:
To use, create a new JavaScript, with the following specifications:
Name: Ajax message delete
Placement: In topics;

Code: Select all

 *! Delete post with AJAX.
 *  @author Luiz
 *  @licence MIT
 *  Copyright (c) Luiz Felipe | All rights reserved.
(function ($) {
  'use strict';
  $(function () {
    $('.post a[href$="mode=delete"]')
      .on('click', function (event) {
        var $this = $(this);
        var $post = $this.parents('.post');
        var $pid  = $this.attr('href').replace(/^\/post\?p=(\d+)&.+/gi, '$1');
        var conf  = confirm('Are you sure that you want to delete a message?');
        if (!conf) {
          console.info('A postagem de ID ' + $pid + ' não foi deletada.');
          return false;
        $.post('/post', {
          mode: 'delete',
          p: $pid,
          confirm: 1
          .done(function () {
          .fail(function () {
              '[AJAX ERROR] Houve um erro ao tentar excluir a postagem de número ' + $pid,
              'Atualize a página e tente novamente.'
Closing Notes:

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest