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.