Several types of contenttype of response

Source: Internet
Author: User
Tags rfc

In AJAX development, when requesting a server-side response, the practice for each return type specification is to specify the response contenttype on the service side. (Of course you don't specify the vast majority of cases, especially when you return "non-XML").

There are several situations that you often encounter:
1, the service side needs to return a section of ordinary text to the client, content-type= "Text/plain"
2, the server needs to return a section of HTML code to the client, content-type= "text/html"
3, the server needs to return a section of XML code to the client, content-type= "Text/xml"
4, the server needs to return a section of JavaScript code to the client
5, the server needs to return a section of JSON string to the client

We mainly discuss returning JavaScript code and JSON objects.

The contentType of JavaScript should be application/javascript according to the most standard. The commonly used text/javascript have been defined as obsolete by the RfC.

But it is not recommended to use application/javascript here for the time being. Let's continue to use Text/javascript as well. Because many old browsers don't support Application/javascript. And all browsers support Text/javascript. Choose between standard and extensive compatibility.

The common contentType of JSON are: Text/json & Text/javascript.
But this text/json actually does not exist at all, and text/javascript at some times the client processing can be ambiguous. For the contenttype of JSON, the standard notation defined in the RFC is: Application/json.
There is no doubt that we should choose the Application/json of the standard wording.


the use of @ Basic Use "@123456" indicates that the output 123456 to the page "@ Chinese 中文版" means the output "Chinese 中文版" to the page Standardized ContentType "@json: xxxx", "@applicaiton/x-json:xxxx" indicates that the output content-type is a Application/x-json xxx string to the client "@xml: xxxx", "@ Application/xml:xxxx "indicates that the output Content-type is a application/xml xxxx string to the client" @plain: xxxx "," @text: xxxxx "," @text/plain: XXXXX "indicates output content-type as Text/plain string to client" @xxxxx "," @html: xxxx "," @text/html:xxxxx "indicates output content-type to text/ HTML string to the client

We support the following Content-type:json, XML, HTML, plain, text, all started with text/, such as text/html, Text/plain, Text/javascript, etc. All the application/, such as Applicaton/x-json, are not supported by others. can be added with Charset=utf-8 modifier "@json: Xxxx;charset=utf-8", "@applicaiton/ X-json:xxxx;charset=utf-8 "indicates that the output content-type is a application/x-json;charset=utf-8 xxx string to the client Tip @text/plain:json:xxxxx, @plain: json:xxxxx, @text: Json:xxxxx "Text/plain" to the client for output Content-type json:xxxxx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.