title: Checking if a m3u8 URL is broken using Javascript
body: <p>I am using the following code to determine if an m3u8 URL is broken or not. I test with two different URLs, one that is online and one that is offline. For both cases, my javascript function doesn't alert me that file is found or not and firefox debugs doesn't give me any error but status variable always shows 0. Could anyone tell me what I am doing wrong here?</p>
  
  <p>Edit:</p>
  
  <pre><code>for offline url i get this header response(in httpfox developer tool) :HTTP/1.1 404 Not Found
  for online url i get this header response(in httpfox developer tool) :HTTP/1.1 200 OK
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code> &lt;head&gt;
      &lt;script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"&gt;&lt;/script&gt;
      &lt;script&gt;
      function testFunction() {
  
  
      //m="http://someothersite.com/offline.m3u8";
      m="http://somesite.com/workingfile.m3u8";
  
      //now we checking if the file exist
  
      UrlExists(m, function(status){
       alert('status:'+status);
          if(status === 200){
             // file was found
             alert('file found'+m);
  
          }
          else if(status === 404){
             // 404 not found
             alert('file not found'+m);
  
  
          }
      });
  
      function UrlExists(url, cb){
          jQuery.ajax({
              url:      url,
              dataType: 'text',
              type:     'GET',
              complete:  function(xhr){
              alert(+xhr.status);
                  if(typeof cb === 'function')
                     cb.apply(this, [xhr.status]);
  
              }
          });
      }
  
  
      }// end of main
  
      &lt;/script&gt;
  
  
  
  
      &lt;/head&gt;
      &lt;body&gt;
      &lt;button onclick="testFunction()"&gt;Click me&lt;/button&gt;
      &lt;/html&gt;
  </code></pre>