0

In my MVC4 web app I'm using FineUploader to upload files.

When a file is uploaded I send a json response from my controller like so:

return this.Json(packageUploadResult, "text/plain", System.Text.Encoding.UTF8);

I had to modify "application/json" to "text/plain" because I was getting "Save As" "Open" options in IE (info here). ONLY IN IE. It works fine in all other browsers.

View:

...
        }).on('complete', function (event, id, filename, json) {
            if (json.success) {
                if (json.IsSignature) {
                    alert("IN");
                }
...

How can I parse Json response to make it work in IE:

sample response:

{"PackageErrorType":0,"PackageId":"AGI-MM-CFG-NUB-2.0.1.2.2","SignatureMatch":false,"IsSignature":false,"success":true}
Community
  • 1
  • 1
ShaneKm
  • 20,823
  • 43
  • 167
  • 296

1 Answers1

0

You could parse the text/plain returned by the server using the $.parseJSON method:

var json = $.parseJSON(textReturnedByServer);
if (json.success) {
    if (json.IsSignature) {
        alert("IN");
    }
}

Of course you should do this only for the legacy browsers that do not support HTML5 File API such as Internet Explorer.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • when I parse it i get null in json variable. this is what I see in IE's console: [FineUploader] converting iframe's innerHTML to JSON [FineUploader] innerHTML =
    {"PackageErrorType":0,"PackageId":"AGI-MM-GM-RTB-2.0.3.1.4","SignatureMatch":false,"IsSignature":false,"success":true}
    Could it be because of the
     tag?? if so how do I parse it?
    – ShaneKm Feb 26 '13 at 07:35
  • Yes, it's because of the pre tag. You could filter it out. – Darin Dimitrov Feb 26 '13 at 07:38