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.
This question is related to
jquery
asp.net-mvc
ajax
asp.net-ajax
internet-explorer
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.
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.
You could see the response in Fiddler: http://www.fiddler2.com/fiddler2/
That's nice tool for such things!
I just had the same issue with an XMLHttpRequest. The site functions flawlessly in Chrome and FF, and in dozens upon dozens of Internet Explorer browsers in production. This ONE machine (the one our company is setting up to be a demo machine, of course) decided that it was going to prompt to save the json response to an ajax request.
The accepted regedit solution below fixed it. Thanks.
Above solution was missing thing, and below code should work in every situation:
Windows Registry Editor Version 5.00
;
; Tell IE to open JSON documents in the browser.
; 25336920-03F9-11cf-8FD0-00AA00686F13 is the CLSID for the "Browse in place" .
;
[HKEY_CLASSES_ROOT\MIME\Database\Content Type\application/json]
"CLSID"="{25336920-03F9-11cf-8FD0-00AA00686F13}"
"Encoding"=hex:08,00,00,00
[HKEY_CLASSES_ROOT\MIME\Database\Content Type\application/x-json]
"CLSID"="{25336920-03F9-11cf-8FD0-00AA00686F13}"
"Encoding"=hex:08,00,00,00
[HKEY_CLASSES_ROOT\MIME\Database\Content Type\text/json]
"CLSID"="{25336920-03F9-11cf-8FD0-00AA00686F13}"
"Encoding"=hex:08,00,00,00
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.
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:
header("Content-type: text/html; charset=iso-8859-1");
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:
$.getJSON (
"<? site_url php echo (" ajax / tipoMenu ")?>"
{contentType: 'text / html; charset = utf-8'},
function (result) {
hugs
Changing IE's JSON mime-type settings will effect the way IE treats all JSON responses.
Changing the mime-type header to text/html will effectively tell any browser that the JSON response you are returning is not JSON but plain text.
Neither options are preferable.
Instead you would want to use a plugin or tool like the above mentioned Fiddler or any other network traffic inspector proxy where you can choose each time how to process the JSON response.
Source: Stackoverflow.com