网络:contentType,dataType,Accept区别

来源:互联网 发布:淘宝卖明星周边违法吗 编辑:程序博客网 时间:2024/06/01 09:04

ContentType


When sending data to the server, use this content type.
Default is “application/x-www-form-urlencoded;

DataType


The type of data that you’re expecting back from the server.
If none is specified, jQuery will try to infer it based on the MIME type of the response (an XML MIME type will yield XML, in 1.4 JSON will yield a JavaScript object, in 1.4 script will execute the script, and anything else will be returned as a string).

Accept


accepts (default: depends on DataType) Type: PlainObject The content type sent in the request header that*** tells the server what kind of response it will accept in return.*

总结


  1. contentType: 告诉服务器,我要发什么类型的数据
  2. dataType:告诉服务器,我要想什么类型的数据,如果没有指定,那么会自动推断是返回 XML,还是JSON,还是script,还是String。
  3. Accept:告诉服务器,能接受什么类型。

参考


  • DataType vs ContentType in jquery ajax [duplicate]
  • dataType vs accepts - Ajax Request
0 1