2012-09-30 236 views
5

可能重複:
The right JSON content type?JSON的正確MIME類型?

我的JSON是隻顯示有問題 「的Content-Type:text/html的」 我是在本地主機上,我的網上的代碼測試

header('Access-Control-Allow-Origin: *'); 

header('Content-Type: application/javascript'); 
//header('Content-type: text/javascript'); 
//header('Content-type: application/json'); 
+0

爲什麼不使用'application/json'? – think123

+0

取消最後一行 – diEcho

+2

[Duplicate](http://stackoverflow.com/q/477816/1077789) – Isuru

回答

1

The application/json JavaScript Object Notation(JSON)的媒體類型

header('Content-type: application/json'); 

再檢查一下這個從IANA

好讀:

Application Media Types

3

使用本

header('Content-type: application/json'); 

JSON數據

+0

它不起作用 – user1709424

+0

@ user1709424你能發表一些代碼嗎? –

+0

<?php 要求'include/jamroom-include.inc.php'; header('Access-Control-Allow-Origin:*'); // header('Access-Control-Allow-Methods:*'); // content header header('Content-Type:application/javascript'); header('Content-type:text/*'); header('Content-type:application/*'); header('Content-Type:application/json'); header('Content-Type:application/x-javascript'); header('Content-Type:text/javascript'); header('Content-Type:text/x-javascript'); header('Content-Type:text/x-json'); – user1709424

1

JSON的MIME類型爲application/json