tp_servicedesk/public/js/ticket_view.js

31 lines
1.0 KiB
JavaScript
Raw Normal View History

2025-02-16 22:07:02 +00:00
document.addEventListener('DOMContentLoaded', function(){
const ticket_id = window.location.pathname.split('/')[2];
const comments_url = `/ticket/${ticket_id}/comments`;
const attachments_url = `/ticket/${ticket_id}/attachments`;
function ajax(url, containerID){
fetch(url)
.then(response => {
if(!response.ok){
throw new Error('Network response was not ok.');
}
return response.text();
})
.then(html => {
const container_el = document.getElementById(containerID);
if(container_el){
container_el.innerHTML += html;
} else {
throw new Error('Coments container does not exist');
}
})
.catch(error => {
console.log('Error fetching comments', error);
});
}
ajax(attachments_url, 'attachments')
ajax(comments_url, 'comments')
});