IE가 응용 프로그램 / json을 다운로드하지 않고 단순히 표시하도록 어떻게 확신 할 수 있습니까?
AJAX를 사용하는 jQuery 앱을 디버깅하는 동안 종종 서비스에서 브라우저로 반환되는 json을 볼 필요가 있습니다. 따라서 JSON 데이터의 URL을 주소 표시 줄에 드롭합니다.
이것은 코딩 오류가 발생하면 브라우저에서 ASPNET 진단을 볼 수 있기 때문에 ASPNET에 좋습니다.
그러나 서버 측 코드가 올바르게 작동하고 실제로 JSON을 반환하면 IE에서 다운로드하라는 메시지를 표시하므로 응답을 볼 수 없습니다.
즉, IE를 일반 텍스트처럼 표시하지 않도록 할 수 있습니까?
Content-Type 헤더를로 설정하면이 작업을 수행 할 수 있습니다 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.
I found the answer.
You can configure IE8 to display application/json in the browser window by updating the registry. There's no need for an external tool. I haven't tested this broadly, but it works with IE8 on Vista.
To use this, remember, all the usual caveats about updating the registry apply. Stop IE. Then, cut and paste the following into a file, by the name of json-ie.reg
.
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\text/json]
"CLSID"="{25336920-03F9-11cf-8FD0-00AA00686F13}"
"Encoding"=hex:08,00,00,00
Then double-click the .reg file. Restart IE. The new behavior you get when tickling a URL that returns a doc with Content-Type: application/json
or Content-Type: text/json
is like this:
What it does, why it works:
The 25336920-03F9-11cf-8FD0-00AA00686F13
is the CLSID for the "Browse in place" action. Basically this registry entry is telling IE that for docs that have a mime type of application/json, just view it in place. This won't affect any application/json documents downloaded via <script>
tags, or via XHR, and so on.
The CLSID and Encoding keys get the same values used for image/gif
, image/jpeg
, and text/html
.
This hint came from this site, and from Microsoft's article Handling MIME Types in Internet Explorer .
In FF, you don't need an external add-on either. You can just use the view-source:
pseudo-protocol. Enter a URL like this into the address bar:
view-source:http://myserver/MyUrl/That/emits/Application/json
This pseudo-protocol used to be supported in IE, also, until WinXP-sp2, when Microsoft disabled it for security reasons.
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
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.
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.
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.
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.
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.
XMLHttpRequest와 동일한 문제가 발생했습니다. 이 사이트는 Chrome 및 FF에서 완벽하게 작동하며 프로덕션 환경에서 수십 개의 Internet Explorer 브라우저에서 작동합니다. 이 ONE 머신 (당사에서 데모 머신으로 설정 한 머신)은 json 응답을 ajax 요청에 저장하라는 프롬프트를 표시하기로 결정했습니다.
아래의 승인 된 regedit 솔루션이 수정했습니다. 감사.
Fiddler에서 응답을 볼 수 있습니다 : http://www.fiddler2.com/fiddler2/
그런 것들을위한 좋은 도구입니다!
'Programming' 카테고리의 다른 글
stdout으로 인쇄하는 것이 왜 그렇게 느립니까? (0) | 2020.06.03 |
---|---|
힘내 : 추적 된 파일 무시 (0) | 2020.06.03 |
모든 빌드에서 Visual Studio로 T4 템플릿 실행 (0) | 2020.06.03 |
웹 API에서 속성이 직렬화되지 않도록 방지 (0) | 2020.06.02 |
힘내 태그를 확인하면 "분리 HEAD 상태"가됩니다 (0) | 2020.06.02 |