I am just learning ajax and have used short polling to reload a div every 0.5 second to display new data. How do I change this to long polling? I know web sockets would be a better approach but for now i want to use ajax.
function load_messages(){
$.ajax({
url: '{% url 'msgs_json' %}',
datatype: 'json',
type: 'GET',
success: function(body) {
body.forEach(function(b) {
if (b.fields.is_read === false){
console.log("unread message(s)")
$("#inbox").load(location.href + " #inbox");
$("#outbox").load(location.href + " #outbox");
}
});
}
});
}
$(document).ready(function(){
setInterval(load_messages,500);
});