title: AJAX firing no_connection(); too early
body: <p>I have this Google Chrome extension..</p>
  
  <p>manifest.json:</p>
  
  <pre><code>{
    "name": "My extension",
    "manifest_version": 2,
    "version": "1.0",
    "permissions": [
      "tabs", "http://*/*"
    ],
    "browser_action": {
      "default_icon": "icon.png",
      "default_popup": "popup.html"
    },
    "content_scripts": [
      {
        "matches": ["http://*/*", "https://*/*"],
        "js": ["jquery-1.8.3.min.js", "content.js"],
        "run_at": "document_end"
      }
    ]
  }
  </code></pre>
  
  <p>popup.html:</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;title&gt;Getting Started Extension's Popup&lt;/title&gt;
      &lt;style&gt;
        body {
          min-width:357px;
          overflow-x:hidden;
        }
  
        img {
          margin:5px;
          border:2px solid black;
          vertical-align:middle;
          width:75px;
          height:75px;
        }
      &lt;/style&gt;
  
      &lt;!-- JavaScript and HTML must be in separate files for security. --&gt;
      &lt;script src="popup.js"&gt;&lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;div id="ajax"&gt;
      &lt;/div&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>popup.js:</p>
  
  <pre><code>function start() {
      var reg = false;
      if (window.ActiveXObject){
          reg = new ActiveXObject("Microsoft.XMLHTTP");
      }else {
          reg = new XMLHttpRequest();
      }
      reg.open("GET","http://www.dr.dk/",true); // Insert a reference of the php page you wanna get instead of yourpage.php
      reg.send(null);
      reg.onreadystatechange = function () {
          if (reg.readyState == 4 &amp;&amp; reg.status == 200) {
              document.getElementById('ajax').innerHTML = reg.responseText;
          }else {
              no_connection();
          }
      }
  }
  
  function no_connection() {
  
      var reg = false;
      if (window.ActiveXObject){
          reg = new ActiveXObject("Microsoft.XMLHTTP");
      }else {
          reg = new XMLHttpRequest();
      }
      reg.open("GET","no_connection.html",true); // Insert a reference of the php page you wanna get instead of yourpage.php
      reg.send(null);
      reg.onreadystatechange = function () {
          if (reg.readyState == 4 &amp;&amp; reg.status == 200) {
              document.getElementById('ajax').innerHTML = reg.responseText;
          }else {
              document.getElementById('ajax').innerHTML = 'An Unknown Error did happened.';
          }
      }
  }
  
  start();
  </code></pre>
  
  <p>This just always comes up with the content from no_connection.html, but if I out comment the line:</p>
  
  <pre><code>no_connection();
  </code></pre>
  
  <p>From the:</p>
  
  <pre><code>function start();
  </code></pre>
  
  <p>Then it works fine, then it shows the content of <code>http://www.dr.dk/</code></p>
  
  <p>How can this happens, when the <code>no_conncection();</code> is inside a <code>if else</code> statement, how can it overides that then?</p>
  
  <p>Any idea how to fix this issue, as this is getting pretty weird.</p>