Some Questions about the Content-Type of response in Ajax Development

Source: Internet
Author: User

In Ajax development, when requesting responses from the server side, you must specify the response contenttype on the server side for each type of response. (Of course, there is no problem in most cases, especially when "non-xml" is returned ).

We often encounter the following situations:
1. The server must return a piece of plain text to the client. Content-Type = "text/plain"
2. The server needs to return a piece of HTMLCodeTo the client, content-type = "text/html"
3. The server must return an XML code to the client. Content-Type = "text/XML"
4. The server needs to return a piece of JavaScript code to the client.
5. The server must return a JSON string to the client.

We mainly discuss the returned JavaScript code and JSON objects.

The contenttype of JavaScript should be written as application/JavaScript in the most standard way. The commonly used text/JavaScript has been defined as obsolete by RFC.

However, application/JavaScript is not recommended for the moment. it is better to continue using text/JavaScript. because many old Browsers Do not support application/JavaScript. all browsers support text/JavaScript. select the latter between the standard and the 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.

Related Article

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.