$.ajax,将参数dataType的值设为json的作用

发布时间 2023-08-09 08:23:21作者: 信铁寒胜
var response = await $.ajax({type: 'POST',url: url,data: null,contentType: "application/json;charset=UTF-8",dataType: "json"})

  如果后台返回的数据是JSON字符串

设置了dataType: "json"后,返回的response会自动转为JS对象。
如果不设置则是返回的是后台的JSON字符串