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.
I've tried poking around in the iframe objects looking for some sort of status_code
attribute, but haven't been able to find anything like that.
The $.ajax()
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 iframe
method.
You can't get page headers by JS, but you can distinguish error from success: Try something like this:
On server side:
You can't retrieving HTTP status code from loaded "iframe" directly. But when an http error occured, the server will returned nothing to the "iframe". So the iframe has not content. you 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.