Capture connection errors with jquery

0

I have a video carousel made in JQuery that makes an AJAX request, so if the Internet fails, the video stops and the system no longer moves and shows these errors:

I was wondering if there would be any way to capture these errors in JQuery and if they do restart the carousel?

    
asked by Esteban Flores 24.02.2017 в 21:26
source

1 answer

1

You can use the error event of the video itself. This event can be binded to the video elements with the onerror attribute, or by JavaScript with either jQuery or native JavaScript.

<video onerror="miFuncion()">

With jQuery

<script>
$(function(){
  $('video').on('error',function(){
    //lo que quieras hacer aquí
  })
}); 
</script>

With native JavaScript

<script>
  document.onload = function(){
      document.getElementsByTagName("VIDEO").onerror = function (){
          //lo que quieras hacer aquí
      };
  }
</script>
    
answered by 24.02.2017 в 21:45