What is the significance of DataType and ContentType in jquery ajax ?
What is the purpose of both in client side request and Server side response ?

- 1,796
- 2
- 25
- 34
-
Is the content-type and data-type purpose differs between jQuery usage and REST API usage? – sofs1 Jan 13 '19 at 05:06
2 Answers
dataType:
The type of data that you're expecting back from the server.
contentType:
When sending data to the server, use this content type. Default is "application/x-www-form-urlencoded; charset=UTF-8", which is fine for most cases. If you explicitly pass in a content-type to $.ajax(), then it is always sent to the server (even if no data is sent). The W3C XMLHttpRequest specification dictates that the charset is always UTF-8; specifying another charset will not force the browser to change the encoding.

- 3,392
- 3
- 27
- 42
-
Is the content-type and data-type purpose differs between jQuery usage and REST API usage? – sofs1 Jan 13 '19 at 05:06
contentType is used to determine how the payload has to be sent to the server as request parameters or as request body.
dataType is used to tell jQuery what is the return type of the request - to determine how to process the response text before it is sent the the handler methods

- 384,651
- 66
- 527
- 531