Ajax requests do not stop loading

Asked

Viewed 75 times

0

I have been with this problem for many days now, I have a page where externally loads the link from a security camera to display the image on the main page, so far so good, the image shows normally on my page, however, all XHR requests do not work, they stay in "pending" status all the time, probably because the camera link never finishes uploading and then the requests wait for it to finish? , how can I get around the problem? , here’s how I’m calling the video, which even runs on the page normally:

<div id="player">
   <img src="/link-da-camera-aqui" height="420" />
</div>';

Then I try to make the requests to check if there is any new message on the page, it is this request that never finishes loading:

    setInterval(function() {
        jQuery.ajax({
        url: "/verifica-novas-mensagens", success: function(resultado){
        if(resultado === '0'){
        alert('Erro na transmissão do vídeo');
        location.href="/home";
        }
        document.getElementById("novas-mensagens").innerHTML = resultado + "<br>";
        }});
    }, 8000);

The camera image works normally without crashing, but the link from it never finishes charging and unfortunately none XHR works, thanks in advance!

  • in the url, put the name of the file you want

  • I am utilizing URL friendly, in case they already direct to the file, I tried to put the file straight too but it didn’t work

1 answer

1

Try to make the request in the background to not stop the other processes by putting async : true, I do not know why you are using setInterval, if it is possible to remove it:

jQuery.ajax({
    async : true,
    url: "/verifica-novas-mensagens", success: function(resultado){
    if(resultado === '0'){
    alert('Erro na transmissão do vídeo');
    location.href="/home";
    }
    document.getElementById("novas-mensagens").innerHTML = resultado + "<br>";
}});
  • Hi Wictor, I need to check this from time to time, in case I was checking every 8 seconds, the intention is to show the new messages to the user without having to give a refresh always, in this your method the script worked, but I need to run it always on the page

  • " but I need to always run it on the page", I did not understand this part

  • I meant that in case I need to keep sending this request in a certain time interval to bring the messages in "real time", always checking if any new message has arrived

Browser other questions tagged

You are not signed in. Login or sign up in order to post.