Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IE prompts to open or save json result from server

Internet explorer in compatibility mode gets the data from the server in an ajax callback method, and pops-up a dialog if I want to save the data or open. How to get rid of that?

client says:

$.ajax({         type:'POST',         data: $("#UIdlgHolder > form").serialize(),         url: $("#UIdlgHolder > form").attr("action"),         success: function (data, textStatus, jqXHR) {             {                 alert(data.message);             } } 

server answers:

return new JsonResult { Data = new { result = false, message = "Yay!" } }; 
like image 723
iLemming Avatar asked May 24 '11 17:05

iLemming


People also ask

How do I enable JSON in Internet Explorer?

To open a JSON file in an IE window you need to create a wrapper function to open a new window and then to inject the JSON file's text content inside of a <pre> or <code> block.

How do I display JSON data in my browser?

Right click on JSON file, select open, navigate to program you want open with(notepad). Consecutive opens automatically use notepad.

How do I post JSON to the server?

To post JSON data to the server, we need to use the HTTP POST request method and set the correct MIME type for the body. The correct MIME type for JSON is application/json. In this POST JSON example, the Content-Type: application/json request header specifies the media type for the resource in the body.


1 Answers

Even though it's not supposedly the correct way, setting the content type to text/html made IE deal with this correctly for me:

return Json(result, "text/html"); 

Works in all the version that F12 tools gives you in IE9.

like image 98
ItsJason Avatar answered Sep 20 '22 22:09

ItsJason