Ajax中dataType与contentType区别,Axios默认的contentType

1.dataType,是后台接口返回的数据格式,eg:dataType:json

2.contentType,是前台传给后台的数据格式(后台response,返回时,也有数据格式,一般不用管,但当导出文件等时,后台就需要设置对应的contentType数据格式),eg:content-type :application/json,后台用@RequestBody标注model或map,来接收参数。前台需要使用JSON.stringify()【axios貌似不需要JSON.stringify处理,加上也没错】

JSON.stringify(params),将前台参数,转为json字符串,传给后台。

JSON.parse(),将json字符串,转为json对象。

contenType,还有文件,表单,等等对应请求类型的数据格式。

3.axios,contentType默认是application/json

传formData时,要指明contentType为表单的,并且数据需要Qs.stringify处理

 

posted @ 2021-08-23 09:45  对月当歌  阅读(2961)  评论(0)    收藏  举报