M
M
MGXH2020-05-07 07:11:21
JavaScript
MGXH, 2020-05-07 07:11:21

How to pass a unique ID value to ajax?

Messages are displayed on the site, they are taken from the database, I decided to delete messages when clicking on the button in these messages. That is, when you click to delete a message, the value of the ID of this message must be transmitted via Ajax in order to find this message in the database in the PHP handler and delete it. Only now I don’t know how to take and get the ID in Ajax , I tried to get the ID simply through a variable, it selects the very first message, that is, the very first ID . Help, how to display a unique message ID using Ajax ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Peter, 2020-05-07
@MGXH

The message id can be attached to the date attribute of the message in the markup.
Next, you need to hang up a click event that will read the content of the attribute and send its value in a DELETE request to delete the backend.
Sample

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question