title: Cross-subdomain Requests (GET, POST, ...) with Jquery and IFrame
body: <p>I'm trying to develop requests between my main domain (http://foo.com) ans my API (http://api.foo.com).</p>
  
  <p>To bypass the restrictions about cross-subdomain stuff, I use an Iframe, on my main page (http.//foo.com/main.html), pointing on a page iframe.html there : scripts.api.foo.com.</p>
  
  <p><em>(scripts.api.foo.com and foo.com are on the same server, api.foo.com on anothers)</em></p>
  
  <p><strong>>iframe.html :</strong></p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
      &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"&gt;
         &lt;head&gt;
             &lt;title&gt;Iframe&lt;/title&gt;
             &lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt;
             &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"&gt;&lt;/script&gt;
         &lt;/head&gt;
         &lt;body&gt;
          &lt;script type="text/javascript"&gt;
      document.domain = 'foo.com';
      function testIframe()
      {
          $.ajax({
                      url: "http://api.foo.com/utctime",
                      timeout: 7000,
                      complete: function(jqXHR, textStatus){
                          parent.alert(jqXHR.status);}
                  });
      }
          &lt;/script&gt;
         &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>
  
  <p><strong>>main.html :</strong></p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"&gt;
     &lt;head&gt;
         &lt;title&gt;Test&lt;/title&gt;
         &lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt;
         &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"&gt;&lt;/script&gt;
     &lt;/head&gt;
     &lt;body&gt;
      &lt;script type="text/javascript"&gt;
  document.domain = 'foo.com';
  function test()
  {
      pipeFrame.testIframe();
  }
      &lt;/script&gt;
      &lt;iframe style="" src="http://scripts.api.foo.com/iframe.html" width="500" height="50" id="pipeFrame" name="pipeFrame"&gt;&lt;/iframe&gt;
          &lt;form&gt;
             &lt;p&gt;
                 &lt;input type="button" value="Hop" onclick="test();" /&gt;
             &lt;/p&gt;        
          &lt;/form&gt;
  
     &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The alert window always contains "<strong>302</strong>" (Redirect) with Firefox 3.6/Chrome,  "<strong>0</strong>" with IE8 ... Though Firebug tells me my request got a "200 Ok" status (and no response) ...</p>
  
  <p>I've tried, directly on scripts.api.foo.com/iframe.html, to lauch the same request, and got the same status code.</p>
  
  <p>I'm quite frustrated, after vainly searching all over the web a clear way to implement cross-subdomain, or an explanation about those status code ...
  Any help would be welcome.</p>
  
  <p>Thanks a lots for your attention.
  Bye.</p>