美文网首页
ajax请求在IE下请求失败

ajax请求在IE下请求失败

作者: Evan_zhan | 来源:发表于2017-08-21 19:02 被阅读0次

    项目要求兼容IE,但是在IE edge下加载不出数据,debug后发现所有ajax请求都失败,
    {readyState: 0, responseJSON: undefined, status: 0, statusText: "error"}

    image.png

    ajax集中请求代码

       const xhr = ({ url, body = null, method = 'get', contentType = "application/x-www-form-
      urlencoded; charset=UTF-8" }) => {
      const defer = $.Deferred();
    
      const request = $.ajax({
        type: method,
        url: url,
        data: body,
        contentType: contentType,
        dataType: "json",
        xhrFields: {
          withCredentials: true
        }
      })
      .done((data) => {
        if (data && data.errcode === 0) {
          defer.resolve(data.data);
        } else {
          defer.reject(data.errmsg);
        }
      })
      .fail((data) => {
        defer.reject(data.errmsg);
      });
      return {
        request: request,
        promise: defer.promise()
      };
    };
    
    export default xhr;
    

    axios

    不用$.ajax,试了axios,还是一样ie edge加载不出

    下篇:1.Deferred对象使用

    相关文章

      网友评论

          本文标题:ajax请求在IE下请求失败

          本文链接:https://www.haomeiwen.com/subject/gqehdxtx.html