jquery-iframe-transport
jquery-iframe-transport copied to clipboard
XHR object doesn't keep the original response status code
When I do the request its response's status and statusText are still 200 and "OK" even if the server side script return a 500 error (or anyother error code).
Anyway, the response content is fine.
Unfortunately there's no way that I know of to get the status code of a response loaded through an iframe. See for example http://stackoverflow.com/questions/35240/retrieving-http-status-code-from-loaded-iframe-with-javascript.
To expand on what @cmlenz is saying, you need to do some server-side scripting to detect when your form has been submitted via the jquery-iframe-transport's iframe, and have it return the response status and code in the body of your response so that your front-end code can parse it out.
For example, the remotipart gem does exactly this in Rails via a Rack Middleware, so that you don't need any custom code in your app to do this.
- Here is where we detect if it was iframe-submitted
- Here is where we return the response status and code in the body of the response
And when you use the textarea
response as above, you don't need to do anything special in your front-end code since the iframe-transport.js automatically detects when the response is a textarea and parses the status code, etc. for you.