How to display a message after deleting a record using php?

0

I have a page with a data list and for each record I have the delete option. When I click the delete button, before executing the action it checks in a controller file which action was requested to only execute the delete code.

The flow of actions goes something like this:

Button Click = > Controller Verification = > Take Action

I tried to print a message after the code was executed, but the message is displayed on the controller page. This is not right because this page should not display anything, it is just a bridge between the request and the desired action.

To request the deletion I am using the post method. Would it be possible to have the confirmation message appear on the page where the listing exists? If so, how could it be done?

    
asked by anonymous 11.06.2018 / 20:37

1 answer

1

Yes, you can do this using AJAX. The code looks something like this:

jQuery.ajax({
  type: "POST",
  url: URL-DA-SUA-REQUISICAO,
  data: DADOS-DA-SUA-REQUISICAO,
  success: function sucesso(dados) {
    document.write('Concluido')
  },
  error: function erro(error) {
    document.write('Ops, um erro ocorreu')
    console.error(error)
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Note that in this case, the function of the error field will only be called in the event of an error in the request or when the returned HTTP status is an error status.

    
11.06.2018 / 21:11