3

I am using this plugin to let users upload images trough ajax.

To create the uploader and trigger a post this jQuery function is used:

function createUploader() {
        var uploader = new qq.FileUploader({
             element: document.getElementById('file-uploader'),
             allowedExtensions: ['pdf'],
             multiple: false,
             action: '@Url.Action("AjaxUpload", "Upload")',
             onComplete: function(id, fileName, responseJSON){
               window.location.href = responseJSON.message;
            }
        });
    }

Well, in responseJSON.message I am returning the path where the file was uploaded (actually converted) and I am doing a trick with window.location.href to force the browser to show the user DOWNLOAD box for that file.

This works great on FF and Chrome but on IE it says:

Do you want to open or save AjaxUpload from localhost?

And if you press open, instead of getting the file from the specified location, you actually get a file containing responseJSON message.

Any jQuery guru who can give me a clue for this issue?

UPDATE: What I can confirm is that the issue is not with window.location.href = responseJSON.message; because even if I remove this line and put alert('something') the same problems occurs...so instead of parsing onComplete, IE try to open the JSON response...

Spudley
  • 166,037
  • 39
  • 233
  • 307
Cristian Boariu
  • 9,603
  • 14
  • 91
  • 162
  • What's the point of uploading and then downloading the same file? Or are you doing some transformation on it on the server? – Darin Dimitrov May 30 '12 at 19:28
  • yeah, it's a conversion I'm doing: from pdf to word – Cristian Boariu May 30 '12 at 19:29
  • Does your route translate the ActionMethod pointer correctly ? If look through IE source, what does it show ? Also, what's the return type on AjaxUpload method ? – InspiredBy May 30 '12 at 20:02
  • Also.. I'm not familiar with that uploader but if there is a OnFailure event try using that and display the error. – InspiredBy May 30 '12 at 20:05
  • I'm returning a `JsonResult`: `return new JsonResult { Data = new { message = outputFilePathResponse } };` so the response is for instance: `{"message":"/Tmp/0c40d994-6d3e-4fab-a43f-028468cb77e8.doc"}` – Cristian Boariu May 30 '12 at 20:05

1 Answers1

5

Try

return Json(new { Data = new { message = outputFilePathResponse } }, "text/html");

Reference: IE tries to download JSON in ASP. NET MVC 3

Community
  • 1
  • 1
InspiredBy
  • 4,271
  • 6
  • 40
  • 67