title: Stop ajax refresh after 5 minutes
body: <p>I have the following code that refreshes a PHP file every 9 seconds. This works ok but I would like to have a timeout in case a user leaves the page open. It should stop refreshing the call after 5 minutes otherwise it will keep loading my PHP file undefinitely wasting server resources. What is the most simple and efficient way to do this with jQuery?</p>
  <p>Here is my code:</p>
  <pre><code>(function($)
  {
      $(document).ready(function()
      {
          $.ajaxSetup(
              {
                  cache: false,
                  beforeSend: function() {
                      $('#content').show();
                  },
                  complete: function() {
                      $('#content').show();
                  },
                  success: function() {
                      $('#content').show();
                  }
              });
          const $container = $(&quot;#content&quot;);
          $container.load(&quot;example.php&quot;);
          const refreshId = setInterval(function () {
              $container.load('example.php');
  
          }, 9000);
      });
  })(jQuery);
  </code></pre>