Struggling to implement AJAX functionality for cloning an 'item' template. I am attempting to insert an EJS template containing information about the newly cloned item into the main EJS page after each POST request. However, I am having difficulty finding the correct approach to achieve this. I have carefully followed the documentation and have the front-end EJS script in place.
Currently encountering the following error: resp is not defined
The 'itemDisplay' template is used to display all items, and 'inventory-scroll-list' is the div containing all items. 'resp' represents the newly created/cloned item (from Mongoose).
// Cloning item using AJAX (to display new item)
$('.cloneItemButton').click(function () {
const itemId = $(this).attr('id')
$.ajax({
method: 'POST',
url: '/item/' + itemId + "/clone",
success: function (resp) {
console.log('Item Cloned: ' + resp._id)
var html = ejs.render('<%- include("/itemDisplay", { item: resp }); %>')
$('.inventory-scroll-list').append(html)
},
})
})