1 axios 中又一个bug 在get的时候 不会自动带 contentType ,这样会导致服务端识别的时候一些问题

解决办法

    axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'

// 添加请求拦截器
axios.interceptors.request.use((config) => {
  if (config.method == 'get') {
    config.data = true
    config.headers['Content-Type'] = 'application/json'
  }
  return config
}, (error) => {
  // 对请求错误做些什么
  console.log(error)
  return Promise.reject(error)
})

2 jquery ajax 服务端返回的数据如果是嵌套格式,需要指定dataType: 'json', 如果服务端设置了特定返回格式


  function getPromo(obj, fn) {
    console.log(JSON.stringify(obj));
    $.ajax({
      url: '/api/getPromotion.htm',
      contentType: 'application/json',
      type: 'POST',
      dataType: 'json',
      data: JSON.stringify(obj),
      success: function (ret) {
        if (fn) {
          fn(ret)
        }
      }
    });

相关文章:

  • 2022-12-23
  • 2021-12-21
  • 2022-02-27
  • 2022-02-24
  • 2021-12-29
  • 2021-11-21
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-28
  • 2022-12-23
  • 2022-01-17
  • 2021-12-05
  • 2022-01-04
相关资源
相似解决方案