2

Here's my predicament. In my JSP, I am trying to upload a file which in turns goes to a JS function. In my JS function, a dynamic iframe is being created, and has an onload function. The onload function creates a dynamic form element and goes on to submit it.

The underlying web server is IIS and if the file size is large, it throws an HTTP Error 404.13 and I get an HTML response. I want to be handle this and am unwilling to parse the HTML to look for error code. Kindly suggest how I should proceed.

My code looks something like this:

JSP content

<td>
<input type="image" id="uploadfile" src="../images/abc.gif" alt="Upload file" title="Upload File" />
<script type="text/javascript">
    var uploadfile = document.getElementById('uploadfile');
    upload({
        element : uploadfile,
        action : 'upload.jsp',
        onstart : function(filename) {
            document.getElementById("uploaded_file").innerHTML = "Uploading";
        },
        oncomplete : function(response_data) {
            .......//some logic
        }
    });
</script>
</td>

JS content

function upload(d) {
    var g = {
        element : null,
        action : "about:blank",
        action_params : {},
        maxsize : 0,
        onstart : null,
        oncomplete : null,
        dataname : "Filedata",
        target : null,
        zindex : "auto"
    };
    .......//some logic
    var c = document.createElement("div");
    .......//some logic
    c.innerHTML = '<iframe name="frameName" src="about:blank" onload="this.onload_callback()"></iframe>';
    .......//some logic
    var i = c.childNodes[0];
    i.onload_callback = function() {
        .......//some logic
        var a = document.createElement("form");
        .......//some logic
        a.submit();
    }
    .......//some logic
}
Chiranjib
  • 1,763
  • 2
  • 17
  • 29

1 Answers1

0

When you submit the form the browser makes a new top-level request in the iframe, and that request is handled by the browser itself, so you can't access the HTTP return code. What you can do is listening to loading events on the iframe, or (not sure it's under your control) modify the IIS response to return a script that communicates the result to the containing page.

Note that this is going to be somehow difficult to implement and possibly hard to port to different browsers, depending on the supported platforms and the involved domains.

You may submit the form asynchronously via javascript to have full control over the HTTP response.

Community
  • 1
  • 1
Raffaele
  • 20,627
  • 6
  • 47
  • 86
  • Nah, can't fiddle with the response like that. I will try working with the frame then. Thanks for the clue. – Chiranjib Dec 18 '13 at 11:27
  • Actually, querying the service with an XHR is way easier and cleaner than using an iframe – Raffaele Dec 18 '13 at 11:32
  • I got around to analyzing the response, but then IIS was returning me a response code 200 and an error HTML. Maybe there's something I am missing here. Increasing the allowed content size on IIS and implementing Streaming on server side helped me. – Chiranjib Jan 23 '14 at 11:57