In AJAX development, when requesting server-side responses, the practice for each return type specification is to specify response's contenttype on the service side. (Of course not specifying the vast majority of cases is not a problem especially when returning "non-XML").
There are several situations where you often encounter the following:
1, the service side need to return a regular text to client,content-type= "Text/plain"
2, the service side need to return a piece of HTML code to the client, content-type= "text/html"
3, the service side need to return an XML code to the client, content-type= "Text/xml"
4, the service side need to return a piece of JavaScript code to the client
5, the service side need to return a JSON string to the client
We mainly discuss the return of JavaScript code and JSON objects.
The contentType of JavaScript should be application/javascript by the most standard notation. The frequently used Text/javascript has been defined as obsolete by the RfC.
However, it is not recommended to use application/javascript here temporarily. Let's continue to use Text/javascript as well. Because very many old browsers do not support Application/javascript. Text/javascript is supported by all browsers. Between standard and extensive compatibility, choose the latter for the moment.
JSON's ContentType common notation are: Text/json & Text/javascript.
But this text/json in fact does not exist at all, and text/javascript in some cases the client processing will be ambiguous. For JSON contenttype, the standard notation defined in the RFC is: Application/json.
There is no doubt that we should choose the standard wording of the Application/json.
Use basic use of @
- "@123456" means output 123456 to page
- "@ Chinese 中文版" means output "Chinese English" to page
Normalized contenttype
- "@json: xxxx", "@applicaiton/x-json:xxxx" means that the output Content-type is Application/x-json XXX string to the client
- "@xml: xxxx", "@application/xml:xxxx" means the output Content-type to application/xml xxxx string to the client
- "@plain: xxxx", "@text: xxxxx", "@text/plain:xxxxx" means that the output Content-type is a text/plain string to the client
- "@xxxxx", "@html: xxxx", "@text/html:xxxxx" means that the output Content-type is text/html string to the client
We support the following Content-type:json, XML, HTML, plain, text, all start with text/, for example text/html, Text/plain, text/javascript, etc. all with application /start, for example, Applicaton/x-json, etc., others are not supported.
Be able to add, charset=utf-8, etc to modify
- "@json: Xxxx;charset=utf-8", "@applicaiton/x-json:xxxx;charset=utf-8" means that the output Content-type is Application/x-json;charset =utf-8 the XXX string to the client
Skills
- "@text/plain:json:xxxxx", "@plain: Json:xxxxx", "@text: json:xxxxx" means output content-type text/plain "Json:xxxxx" to the client
Several types of contenttype response