31 lines
1.0 KiB
JavaScript
31 lines
1.0 KiB
JavaScript
|
|
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')
|
||
|
|
});
|
||
|
|
|