This is a migrated thread and some comments may be shown as answers.

IE 8 Upload and return error message via JSON

4 Answers 154 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Patrick
Top achievements
Rank 2
Patrick asked on 05 Sep 2013, 03:58 PM
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

4 Answers, 1 is accepted

Sort by
0
T. Tsonev
Telerik team
answered on 09 Sep 2013, 07:06 AM
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!
0
Patrick
Top achievements
Rank 2
answered on 09 Sep 2013, 11:31 AM
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 
0
Accepted
T. Tsonev
Telerik team
answered on 11 Sep 2013, 08:15 AM
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!
0
Patrick
Top achievements
Rank 2
answered on 11 Sep 2013, 10:44 AM
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.
Tags
Upload
Asked by
Patrick
Top achievements
Rank 2
Answers by
T. Tsonev
Telerik team
Patrick
Top achievements
Rank 2
Share this question
or