a question for those more experienced than me. How can I stop the execution of the setInterval having this code and not being able to use a main function? Thanks for your help.
$(".scrivi-messaggio").click(function()
{
var username_utente = $('#username-utente').val();
$('.modal-title').html('Chat di '+username_chat);
setInterval(function()
{
$.get("//localhost/laravel/public/index.php/stampa_messaggi/"+id,
function(data)
{
data_parsed = JSON.parse(data);
var resultHtml = '';
$.each(data_parsed, function(i, el)
{
if(el.id_user === id_user)
{
resultHtml += "<a href='http://localhost/laravel/public/index.php/utente/" + id_user + "' style='font-weight: bold;'>" + username + "</a> " + el.contenuto + "<br />";
}
else
{
resultHtml += "<a href='http://localhost/laravel/public/index.php/utente/" + el.id_user + "' style='font-weight: bold;'>" + username_utente + "</a> " + el.contenuto + "<br />";
}
});
$(".stampa-messaggi").html(resultHtml).show();
});
}, 2000);
});