IE 8 Upload and return error message via JSON

5 posts, 1 answers
  1. Patrick
    Patrick avatar
    19 posts
    Member since:
    Jul 2010

    Posted 05 Sep 2013 Link to this post

    We currently are uploading a file and need to validate before saving it. If all validation passes we save the file and continue as normal. However if it fails we return a custom JSON object of error msgs to the client to correct. This works in IE 10 but not IE 8 (not sure about IE 9).

    Little more info on what we are doing when validation fails – ASP MVC 4.
    1. Set return HTTP Status code to 500 (Internal Svr Error)
    2. To force IIS not to override our result set Response.TrySkipIisCustomErrors= true
    3 . Return our JSON object (content-type of text/plain)

    In IE 10 we get the object back in the xhr and it sees the status code of 500 and fires the error event. However in IE 8 we are getting the fakeXhr and it is determining success based on if it can parse the response as JSON. So of course it's successful and then calls the success event handler for the upload control. Now that it's fired the success event the upload control thinks all is well and updates UI/data to match. 

    So is there a way to:
    1. Return JSON and a status code of 500 and have IE 8 see it as an error regardless of if it can parse the JSON?
    2. In the success mark it really as an error (fire error event) and not have the UI/data update as if it was successful? 

    Any help would be greatly appreciated!
    Patrick
  2. T. Tsonev
    Admin
    T. Tsonev avatar
    2770 posts

    Posted 09 Sep 2013 Link to this post

    Hi,

    The method we use for uploading in IE8/9 (a hidden IFRAME) does not allow access to the server response for failed requests. This is why the Upload requires an OK response even if the server validation has failed.

    If you prefer to keep the JSON response then you need to process it in the success event. There's no way to mark the upload as failed from the success event. We should probably figure out a way to make this possible.

    An alternative approach is to return the error message as plain text. This will get you in the error event handler where you can access it.

    I hope this helps.

    Regards,
    T. Tsonev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Kendo UI is VS 2017 Ready
  4. Patrick
    Patrick avatar
    19 posts
    Member since:
    Jul 2010

    Posted 09 Sep 2013 Link to this post

    Thanks for the response! However seems no clean fix is available at this time. Passing back a string isn't a good workaround because there is no way to tell if it's my error/validation msg or an unhandled exception - without a hacky msg check. If possible the failing/erroring of the call within the success would be great. I think would cover all scenarios! Do you think this is something that will be built into Kendo in the near future?

    Patrick 
  5. Answer
    T. Tsonev
    Admin
    T. Tsonev avatar
    2770 posts

    Posted 11 Sep 2013 Link to this post

    Hi,

    We're thinking of making the success event cancellable. This is easy to do and will allow a transition from a "successful request" to "unsuccessful upload".
    The other option is to impose a convention on the returned JSON, but this feels a bit more restrictive.

    Regards,
    T. Tsonev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  6. Patrick
    Patrick avatar
    19 posts
    Member since:
    Jul 2010

    Posted 11 Sep 2013 Link to this post

    I agree the cancellable approach would be best. Once this is available we'll make great use of it! Thanks for all your info regard this issue.
Back to Top
Kendo UI is VS 2017 Ready