<p>I used the jQuery Form plugin for asynchronous form submission. For forms that contain files, it copies the form to a hidden iframe, submits it, and copies back the iframe's contents. The problem is that I can't figure out how to find what HTTP status code was returned by the server. For example, if the server returns 404, the data from the iframe will be copied as normal and treated as a regular response.</p>

<p>I've tried poking around in the iframe objects looking for some sort of <code>status_code</code> attribute, but haven't been able to find anything like that.</p>

<hr>

<p>The <code>$.ajax()</code> function can't be used, because it does not support uploading files. The only way to asynchronously upload files that I know of is using the hidden <code>iframe</code> method.</p>

[{'answer_id': 1847965, 'author': 'Coyod', 'author_id': 223888, 'author_profile': 'https://Stackoverflow.com/users/223888', 'pm_score': 4, 'selected': False, 'text': '<p>You can\'t get page headers by JS, but you can distinguish error from success:\nTry something like this:</p>\n\n<pre><code>&lt;script type="text/javascript"&gt;\n\n    var uploadStarted = false;\n    function OnUploadStart(){            \n        uploadStarted = true;\n    }\n\n    function OnUploadComplete(state,message){       \n\n       if(state == 1)\n        alert("Success: "+message);     \n       else\n         if(state == 0 &amp;&amp; uploadStarted)\n            alert("Error:"+( message ? message : "unknow" ));\n    }   \n\n&lt;/script&gt;\n\n\n&lt;iframe id="uploader" name="uploader" onload="OnUploadComplete(0)" style="width:0px;height:0px;border:none;"&gt;&lt;/iframe&gt;\n\n&lt;form id="sender" action="/upload.php" method="post" target="uploader" enctype="multipart/form-data" onsubmit="OnUploadStart()"&gt;\n&lt;input type="file" name="files[upload]"/&gt;\n&lt;input type="submit" value="Upload"/&gt;\n&lt;/form&gt;\n</code></pre>\n\n<p>On server side:</p>\n\n<pre><code>/*\n  file: upload.php\n*/\n&lt;?php \n\n   // do some stuff with file       \n\n  print \'&lt;script type="text/javascript"&gt;\';\n  if(success)\n     print \'window.parent.OnUploadComplete(1,"File uploaded!");\';\n  else\n     print \'window.parent.OnUploadComplete(0, "File too large!");\';\n  print  \'&lt;/script&gt;\';\n?&gt;\n</code></pre>\n'}, {'answer_id': 29068651, 'author': 'choi gray', 'author_id': 4674666, 'author_profile': 'https://Stackoverflow.com/users/4674666', 'pm_score': -1, 'selected': False, 'text': '<p>You can\'t retrieving HTTP status code from loaded "iframe" directly.\nBut when an http error occured, the server will returned nothing to the "iframe".\nSo the iframe has not content.\nyou can check the iframe body, when the body of iframe is blank, use ajax with the same url to get the response from server. Then you can retrieve the http status code from response.</p>\n'}]
['https://Stackoverflow.com/questions/35240', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3560/']