While debugging jQuery apps that use AJAX, I often have the need to see the json that is being returned by the service to the browser. So I'll drop the URL for the JSON data into the address bar.
This is nice with ASPNET because in the event of a coding error, I can see the ASPNET diagostic in the browser:
But when the server-side code works correctly and actually returns JSON, IE prompts me to download it, so I can't see the response.
Can I get IE to NOT do that, in other words, to just display it as if it were plain text?
I know I could do this if I set the Content-Type header to be text/plain
.
But this is specifically an the context of an ASPNET MVC app, which sets the response automagically when I use JsonResult on one of my action methods. Also I kinda want to keep the appropriate content-type, and not change it just to support debugging efforts.
FireFox + FireBug is very good for this purpose. For IE there's a developer toolbar which I've never used and intend to use so I cannot provide much feedback.
I had a similar problem. I was using the "$. GetJSON" jQuery and everything worked perfectly in Firefox and Chrome.
But it did not work in IE. So I tried to directly access the URL of json, but in IE it asked if I wanted to download the file.
After much searching I saw that there must be a header in the result with a content-type, in my case, the content-type was:
But when the page that made the request receives this json, in IE, you have to be specified SAME CONTENT-TYPE, in my case was:
hugs
If you are okay with just having IE open the JSON into a notepad, you can change your system's default program for .json files to Notepad.
To do this, create or find a .json file, right mouse click, and select "Open With" or "Choose Default Program."
This might come in handy if you by chance want to use Internet Explorer but your IT company wont let you edit your registry. Otherwise, I recommend the above answers.
Above solution was missing thing, and below code should work in every situation:
Just save it file json.reg, and run to modify your registry.
I use Fiddler with JSONViewer plugin to inspect JSON. I don't think it is possible to make IE behave without fiddling with registry perhaps. Here's some information.
You could see the response in Fiddler: http://www.fiddler2.com/fiddler2/
That's nice tool for such things!