I'm currently tackling a front-end CRUD
RESTful API project and encountering challenges specifically related to the DELETE
and PUT
methods.
While I have successfully managed to implement the GET
and POST
functionalities, utilizing a forms.html
file for posting data and ensuring that my Ajax calls to localhost:3000/submit/
(the location of my form.html
page) properly handle invalid formatting.
The issue lies in incorporating a Delete button within a dynamic table on the front end (each row contains one such button created using JavaScript). I am uncertain how to instruct the system to "delete this row" upon clicking. On the backend, I have an app.delete
route which follows the format: localhost:3000/pokemon/del/7
, where triggering this URL would delete the entry corresponding to the 7th position, for instance. The same logic applies to other entries as well. Are there any recommended documentation or suggestions you can provide to assist me with this task?
My current strategy involves creating a JavaScript loop that iterates through each button, assigning it an ID attribute ("delButton" + j) based on the iteration variable 'j'. This results in having multiple delete buttons labeled as delButton1, delButton2, delButton3, and so forth. Upon click, I plan to execute an Ajax delete request with the endpoint "http://localhost:3000/pokemon/del/" appended with the specific ID number from the button. While this approach seems promising, I remain open to alternative suggestions or solutions to enhance its effectiveness.