The source of the original article is unknown. Anyway, thank you for choosing the author first.
In Ajax development, we often encounter the following situations:
1. The server must return a piece of plain text to the client.
2. The server must return an HTML code to the client.
3. The server must return an XML code to the client.
4. The server must return a piece of JavaScript code to the client.
5. The server must return a JSON string to the client.
For each return type, the standard practice is to specify the contenttype of response on the server.
(Of course, there is no problem in most cases, especially when "non-xml" is returned)
Code
Plain text: text/plain
HTML code: text/html
XML code: text/XML
The above three cases are not controversial, but you should pay attention to the other two cases.
Javascript contenttype should be written in the most standard format: Application/JavaScript.
The commonly used text/JavaScript has been defined as obsolete by RFC.
However, application/JavaScript is not recommended for the moment.
Because many old Browsers Do not support application/JavaScript
All browsers support text/JavaScript.
Select the latter for the moment between the standard and extensive compatibility.
JSON contenttype is commonly written in the following ways: text/JSON & text/JavaScript.
However, this text/JSON does not exist at all, and text/JavaScript may be ambiguous when processed by the client.
For JSON contenttype, the standard syntax defined in RFC is: Application/JSON.
There is no doubt that we should select the standard format of application/JSON
Finally, a list of contenttypes is provided:
Common:
Text/plain <br/> text/html <br/> text/XML <br/> test/JavaScript <br/> application/JSON <br/> image/GIF <br /> image/JPEG <br/>
List:
". * "=" Application/octet-stream "<br/> ". 001 "=" application/x-001 "<br/> ". 301 "=" application/x-301 "<br/> ". 323 "=" text/h323 "<br/> ". 906 "=" application/x-906 "<br/> ". 907 "=" Drawing/907 "<br/> ". a11 "=" application/x-a11 "<br/> ". ACP "=" audio/X-Mei-AAC "<br/> ". AI "=" application/postscript "<br/> ". AIF "=" audio/AIFF "<br/> ". aifc "=" audio/AIFF "<br/> ". AIFF "=" audio/AIFF "<br/> ". anv "=" application/X-anv "<br/> ". asa "=" text/asa "<br/> ". ASF "=" Video/X-MS-ASF "<br/> ". ASP "=" text/asp "<br/> ". ASX "=" Video/X-MS-ASF "<br/> ". au "=" audio/basic "<br/> ". avi "=" Video/Avi "<br/> ". AWF "=" application/vnd. adobe. workflow "<br/> ". biz "=" text/XML "<br/> ". BMP "=" application/X-BMP "<br/> ". bot "=" application/X-bot "<br/> ". c4t "=" application/x-c4t "<br/> ". c90 "=" application/x-c90 "<br/> ". cal "=" application/X-cals "<br/> ". cat "=" application/vnd. ms-pki.seccat "<br/> ". CDF "=" application/X-netcdf "<br/> ". CDR "=" application/X-CDR "<br/> ". cel "=" application/X-Cel "<br/> ". CER "=" application/x-x509-ca-cert "<br/> ". cg4 "=" application/x-g4 "<br/> ". CGM "=" application/X-CGM "<br/> ". CIT "=" application/X-CIT "<br/> ". class "=" Java/* "<br/> ". CRF "=" text/XML "<br/> ". CMP "=" application/X-CMP "<br/> ". cmx "=" application/X-cmx "<br/> ". COT "=" application/X-cot "<br/> ". CRL "=" application/pkix-CRL "<br/> ". CRT "=" application/x-x509-ca-cert "<br/> ". CSI "=" application/X-CSI "<br/> ". CSS "=" text/CSS "<br/> ". cut "=" application/X-cut "<br/> ". DBF "=" application/X-DBF "<br/> ". DBM "=" application/X-dBm "<br/> ". dbx "=" application/X-dbx "<br/> ". DCD "=" text/XML "<br/> ". dcx "=" application/X-dcx "<br/> ". der "=" application/x-x509-ca-cert "<br/> ". dgn "=" application/X-dgn "<br/> ". diB "=" application/X-dib "<br/> ". DLL "=" application/X-msdownload "<br/> ". doc "=" application/MSWord "<br/> ". dot "=" application/MSWord "<br/> ". drw "=" application/X-drw "<br/> ". DTD "=" text/XML "<br/> ". dwF "=" model/vnd. dwF "<br/> ". dwF "=" application/X-DwF "<br/> ". DWG "=" application/X-DWG "<br/> ". dxb "=" application/X-dxb "<br/> ". DXF "=" application/X-DXF "<br/> ". edn "=" application/vnd. adobe. edn "<br/> ". EMF "=" application/X-EMF "<br/> ". eml "=" message/rfc822 "<br/> ". ent "=" text/XML "<br/> ". EPI "=" application/X-epi "<br/> ". EPS "=" application/X-Ps "<br/> ". EPS "=" application/postscript "<br/> ". ETD "=" application/X-EBX "<br/> ". EXE "=" application/X-msdownload "<br/> ". fax "=" image/fax "<br/> ". FDF "=" application/vnd. FDF "<br/> ". fif "=" application/Fractals "<br/> ". FO "=" text/XML "<br/> ". FRM "=" application/X-frm "<br/> ". g4 "=" application/x-g4 "<br/> ". GBR "=" application/X-GBR "<br/> ". GCD "=" application/X-GCD "<br/> ". GIF "=" image/GIF "<br/> ". gl2 "=" application/x-gl2 "<br/> ". gp4 "=" application/x-gp4 "<br/> ". hgl "=" application/X-hgl "<br/> ". hmr "=" application/X-hmr "<br/> ". HPG "=" application/X-HPGL "<br/> ". hpl "=" application/X-hpl "<br/> ". hqx "=" application/mac-binhex40 "<br/> ". HRF "=" application/X-HRF "<br/> ". HTA "=" application/HTA "<br/> ". HTC "=" text/X-component "<br/> ". htm "=" text/html "<br/> ". html "=" text/html "<br/> ". htt "=" text/webviewhtml "<br/> ". htx "=" text/html "<br/> ". ICB "=" application/X-ICB "<br/> ". ICO "=" image/X-icon "<br/> ". ICO "=" application/X-ICO "<br/> ". IFF "=" application/X-Iff "<br/> ". ig4 "=" application/x-g4 "<br/> ". IG "=" application/X-ig "<br/> ". III "=" application/X-iPhone "<br/> ". IMG "=" application/X-IMG "<br/> ". INS "=" application/X-Internet-signup "<br/> ". ISP "=" application/X-Internet-signup "<br/> ". IVF "=" Video/X-IVF "<br/> ". java "=" Java/* "<br/> ". jfif "=" image/JPEG "<br/> ". jpe "=" image/JPEG "<br/> ". jpe "=" application/X-jpe "<br/> ". JPEG "=" image/JPEG "<br/> ". jpg "=" image/JPEG "<br/> ". jpg "=" application/X-jpg "<br/> ". JS "=" application/X-JavaScript "<br/> ". JSP "=" text/html "<br/> ". la1 "=" audio/X-liquid-file "<br/> ". lar "=" application/X-laplayer-Reg "<br/> ". latex "=" application/X-latex "<br/> ". LAVS "=" audio/X-liquid-secure "<br/> ". LBM "=" application/X-LBM "<br/> ". lmsff "=" audio/X-la-LMS "<br/> ". ls "=" application/X-JavaScript "<br/> ". LTr "=" application/X-LTR "<br/> ". m1v "=" Video/X-mPEG "<br/> ". m2v "=" Video/X-mPEG "<br/> ". m3U "=" audio/mpegurl "<br/> ". m4e "=" Video/MPEG4 "<br/> ". mac "=" application/X-Mac "<br/> ". man "=" application/X-troff-man "<br/> ". math "=" text/XML "<br/> ". mdb "=" application/msaccess "<br/> ". mdb "=" application/X-mdb "<br/> ". MFP "=" application/X-Shockwave-flash "<br/> ". MHT "=" message/rfc822 "<br/> ". MHTML "=" message/rfc822 "<br/> ". mi "=" application/X-MI "<br/> ". mid "=" audio/mid "<br/> ". midi "=" audio/mid "<br/> ". mil "=" application/X-mil "<br/> ". MML "=" text/XML "<br/> ". MND "=" audio/X-MusicNet-download "<br/> ". MNS "=" audio/X-MusicNet-stream "<br/> ". mocha "=" application/X-JavaScript "<br/> ". movie "=" Video/X-SGI-movie "<br/> ". MP1 "=" audio/MP1 "<br/> ". MP2 "=" audio/MP2 "<br/> ". mp2v "=" Video/MPEG "<br/> ". MP3 "=" audio/MP3 "<br/> ". MP4 "=" Video/MPEG4 "<br/> ". MPa "=" Video/X-MPG "<br/> ". MPD "=" application/vnd. MS-project "<br/> ". MPE "=" Video/X-mPEG "<br/> ". MPEG "=" Video/MPG "<br/> ". MPG "=" Video/MPG "<br/> ". mpga "=" audio/RN-mPEG "<br/> ". MPP "=" application/vnd. MS-project "<br/> ". MPs "=" Video/X-mPEG "<br/> ". MPT "=" application/vnd. MS-project "<br/> ". MPV "=" Video/MPG "<br/> ". MPV2 "=" Video/MPEG "<br/> ". MPW "=" application/vnd. MS-project "<br/> ". MPX "=" application/vnd. MS-project "<br/> ". (delete). (delete ". mxp "=" application/X-mmxp "<br/> ". net "=" image/pnetvue "<br/> ". NRF "=" application/X-NRF "<br/> ". NWS "=" message/rfc822 "<br/> ". ODC "=" text/X-MS-ODC "<br/> ". out "=" application/X-out "<br/> ". p10 "=" application/pkcs10 "<br/> ". p12 "=" application/x-pkcs12 "<br/> ". p7b "=" application/x-pkcs7-certificates "<br/> ". p7c "=" application/pkcs7-mime "<br/> ". p7m "=" application/pkcs7-mime "<br/> ". p7r "=" application/x-pkcs7-certreqresp "<br/> ". p7s "=" application/pkcs7-signature "<br/> ". pc5 "=" application/x-pc5 "<br/> ". PCI "=" application/X-PCI "<br/> ". PCL "=" application/X-PCL "<br/> ". PCX "=" application/X-PCX "<br/> ". PDF "=" application/pdf "<br/> ". PDF "=" application/pdf "<br/> ". PDX "=" application/vnd. adobe. PDX "<br/> ". pfx "=" application/x-pkcs12 "<br/> ". PGL "=" application/X-PGL "<br/> ". PIC "=" application/X-pic "<br/> ". PKO "=" application/vnd. ms-pki.pko "<br/> ". PL "=" application/X-perl "<br/> ". PLG "=" text/html "<br/> ". pls "=" audio/scpls "<br/> ". PLT "=" application/X-PLT "<br/> ". PNG "=" image/PNG "<br/> ". PNG "=" application/X-PNG "<br/> ". pot "=" application/vnd. MS-PowerPoint "<br/> ". PPA "=" application/vnd. MS-PowerPoint "<br/> ". PPM "=" application/X-ppm "<br/> ". PPS "=" application/vnd. MS-PowerPoint "<br/> ". ppt "=" application/vnd. MS-PowerPoint "<br/> ". ppt "=" application/X-ppt "<br/> ". PR "=" application/X-Pr "<br/> ". PRF "=" application/pics-Rules "<br/> ". PRN "=" application/X-PRN "<br/> ". PRT "=" application/X-PRT "<br/> ". ps "=" application/X-Ps "<br/> ". ps "=" application/postscript "<br/> ". PTN "=" application/X-PTN "<br/> ". pwz "=" application/vnd. MS-PowerPoint "<br/> ". r3t "=" text/vnd. rn-realtext3d "<br/> ". RA "=" audio/vnd. rn-RealAudio "<br/> ". ram "=" audio/X-PN-RealAudio "<br/> ". RAS "=" application/X-ras "<br/> ". rat "=" application/rat-file "<br/> ". RDF "=" text/XML "<br/> ". REC "=" application/vnd. rn-recording "<br/> ". red "=" application/X-red "<br/> ". RGB "=" application/X-RGB "<br/> ". RJS "=" application/vnd. rn-RealSystem-RJS "<br/> ". rjt "=" application/vnd. rn-RealSystem-rjt "<br/> ". RLC "=" application/X-RLC "<br/> ". rle "=" application/X-RLE "<br/> ". RM "=" application/vnd. rn-RealMedia "<br/> ". RMF "=" application/vnd. adobe. RMF "<br/> ". RMI "=" audio/mid "<br/> ". rmj "=" application/vnd. rn-RealSystem-rmj "<br/> ". RMM "=" audio/X-PN-RealAudio "<br/> ". RMP "=" application/vnd. rn-rn_music_package "<br/> ". RMS "=" application/vnd. rn-RealMedia-secure "<br/> ". rmvb "=" application/vnd. rn-RealMedia-VBr "<br/> ". RMX "=" application/vnd. rn-RealSystem-RMX "<br/> ". rnx "=" application/vnd. rn-RealPlayer "<br/> ". RP "=" image/vnd. rn-realpix "<br/> ". rpm "=" audio/X-PN-RealAudio-plugin "<br/> ". rsml "=" application/vnd. rn-rsml "<br/> ". RT "=" text/vnd. rn-RealText "<br/> ". rtf "=" application/MSWord "<br/> ". rtf "=" application/X-rtf "<br/> ". RV "=" Video/vnd. rn-realvideo "<br/> ". sam "=" application/X-Sam "<br/> ". sat "=" application/X-sat "<br/> ". SDP "=" application/SDP "<br/> ". SDW "=" application/X-SDW "<br/> ". sit "=" application/X-stuffit "<br/> ". SLB "=" application/X-SLB "<br/> ". SLD "=" application/X-SLD "<br/> ". SLK "=" Drawing/X-SLK "<br/> ". SMI "=" application/smil "<br/> ". SMIL "=" application/smil "<br/> ". SMK "=" application/X-SMK "<br/> ". SND "=" audio/basic "<br/> ". sol "=" text/plain "<br/> ". sor "=" text/plain "<br/> ". SPC "=" application/x-pkcs7-certificates "<br/> ". SPL "=" application/futuresplash "<br/> ". SPP "=" text/XML "<br/> ". SSM "=" application/streamingmedia "<br/> ". SST "=" application/vnd. ms-pki.certstore "<br/> ". STL "=" application/vnd. ms-pki.stl "<br/> ". stm "=" text/html "<br/> ". sty "=" application/X-Sty "<br/> ". SVG "=" text/XML "<br/> ". SWF "=" application/X-Shockwave-flash "<br/> ". TDF "=" application/X-TDF "<br/> ". TG4 "=" application/x-tg4 "<br/> ". TGA "=" application/X-TGA "<br/> ". TIF "=" image/tiff "<br/> ". TIF "=" application/X-TIF "<br/> ". tiff "=" image/tiff "<br/> ". TLD "=" text/XML "<br/> ". top "=" Drawing/X-top "<br/> ". torrent "=" application/X-BitTorrent "<br/> ". TSD "=" text/XML "<br/> ". TXT "=" text/plain "<br/> ". uin "=" application/X-ICQ "<br/> ". ULS "=" text/iuls "<br/> ". VCF "=" text/X-vCard "<br/> ". VDA "=" application/X-VDA "<br/> ". vdx "=" application/vnd. visio "<br/> ". VML "=" text/XML "<br/> ". VPG "=" application/x-vpeg005 "<br/> ". sealing Method "=" application/vnd. visio "<br/> ". sealing "=" application/X-sealing "<br/> ". VSS "=" application/vnd. visio "<br/> ". VST "=" application/vnd. visio "<br/> ". VST "=" application/X-VST "<br/> ". vsw "=" application/vnd. visio "<br/> ". vsx "=" application/vnd. visio "<br/> ". vtx "=" application/vnd. visio "<br/> ". VXML "=" text/XML "<br/> ". wav "=" audio/WAV "<br/> ". wax "=" audio/X-MS-wax "<br/> ". wb1 "=" application/x-wb1 "<br/> ". wb2 "=" application/x-wb2 "<br/> ". wb3 "=" application/x-wb3 "<br/> ". wbmp "=" image/vnd. WAP. wbmp "<br/> ". wiz "=" application/MSWord "<br/> ". wk3 "=" application/x-wk3 "<br/> ". wk4 "=" application/x-wk4 "<br/> ". wkq "=" application/X-wkq "<br/> ". wks "=" application/X-wks "<br/> ". wm "=" Video/X-MS-WM "<br/> ". WMA "=" audio/X-MS-WMA "<br/> ". WMD "=" application/X-MS-WMD "<br/> ". WMF "=" application/X-WMF "<br/> ". WML "=" text/vnd. WAP. WML "<br/> ". WMV "=" Video/X-MS-WMV "<br/> ". wmx "=" Video/X-MS-wmx "<br/> ". WMZ "=" application/X-MS-WMZ "<br/> ". WP6 "=" application/x-wp6 "<br/> ". WPD "=" application/X-WPD "<br/> ". WPG "=" application/X-WPG "<br/> ". WPL "=" application/vnd. MS-WPL "<br/> ". wq1 "=" application/x-wq1 "<br/> ". wr1 "=" application/x-wr1 "<br/> ". WRI "=" application/X-WRI "<br/> ". wrk "=" application/X-wrk "<br/> ". WS "=" application/X-ws "<br/> ". WS2 "=" application/X-ws "<br/> ". WSC "=" text/scriptlet "<br/> ". WSDL "=" text/XML "<br/> ". WVX "=" Video/X-MS-WVX "<br/> ". XDP "=" application/vnd. adobe. XDP "<br/> ". XDR "=" text/XML "<br/> ". XFD "=" application/vnd. adobe. XFD "<br/> ". XFDF "=" application/vnd. adobe. XFDF "<br/> ". XHTML "=" text/html "<br/> ". xls "=" application/vnd. MS-excel "<br/> ". xls "=" application/X-xls "<br/> ". xlw "=" application/X-xlw "<br/> ". XML "=" text/XML "<br/> ". xpl "=" audio/scpls "<br/> ". XQ "=" text/XML "<br/> ". xql "=" text/XML "<br/> ". XQuery "=" text/XML "<br/> ". XSD "=" text/XML "<br/> ". XSL "=" text/XML "<br/> ". XSLT "=" text/XML "<br/> ". xwd "=" application/X-xwd "<br/> ". x_ B "=" application/x-x_ B "<br/> ". x_t "=" application/x-x_t"