How can I convince IE to simply display application/json rather than offer to download it?

前端 未结 9 538
野的像风
野的像风 2020-11-22 14:57

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 da

相关标签:
9条回答
  • 2020-11-22 15:33

    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.

    0 讨论(0)
  • 2020-11-22 15:34

    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.

    0 讨论(0)
  • 2020-11-22 15:39

    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.

    0 讨论(0)
  • 2020-11-22 15:41

    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.

    0 讨论(0)
  • 2020-11-22 15:42

    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.

    0 讨论(0)
  • 2020-11-22 15:43

    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.

    0 讨论(0)
提交回复
热议问题