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

Asked

Viewed 105 times

0

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

The stock flow goes something like this:

Click on the Button => Checking in the Controller => Executes Action

I tried to print a message on screen after code execution, but the message is displayed on the controller page. Which is not certain because this page should not display anything, being only a bridge between the request and the desired action.

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

  • This is an Ajax?

  • @dvd I do this directly in PHP, in which case I don’t use Ajax in the request.

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>

Remember, in this case, the field function error will only be called if an error occurs in the request or when the returned HTTP status is an error status.

  • Thank you very much, solved my problem.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.