简体   繁体   English

ReactJS Redux Saga获取API

[英]ReactJS redux saga fetch api

I have following code in my ReactJS app that is not working on IE11 browser. 我的ReactJS应用程序中有以下代码无法在IE11浏览器上运行。 The problem is with fetch call on IE11 browser. 问题是fetch在IE11浏览器中调用。 Application is not making the API call to server. 应用程序未对服务器进行API调用。

It works great on Chrome, Firefox, Safari and Edge. 它在Chrome,Firefox,Safari和Edge上运行良好。 Could anyone please suggest what steps do I need to perform to support IE11 also? 有人可以建议我还需要执行哪些步骤来支持IE11吗? Thanks. 谢谢。

function toQueryString(obj) {
    var parts = [];
    for (var i in obj) {
        if (obj.hasOwnProperty(i)) {
            parts.push(encodeURIComponent(i) + "=" + encodeURIComponent(obj[i]));
        }
    }
    return parts.join("&");
}
var options = new Object;
options.searchoptions = JSON.stringify(searchoptions);
options.limit = limit;
options.offset = offset;
var optionstr = toQueryString(options);

return fetch(`${SERVER_URL}/api/resource/?${optionstr}`, {
  method: 'get',
  dataType: 'json',
  credentials: 'same-origin',
  headers: {
    'Accept': 'application/json',
    'contentType': 'application/json',
    'X-CSRFToken': getCookie('csrftoken')
  }
}).then(response => {
    return response.json();
  }).then(response => {
  var data = JSON.parse(response);
  return data;
}).then(json => {
  return json;
});

fetch is not supported in IE 11. but you can use a polyfill https://github.com/github/fetch IE 11不支持fetch,但是您可以使用polyfill https://github.com/github/fetch

You might also need a promise polyfill like babel-polyfill. 您可能还需要像babel-polyfill这样的诺言polyfill。 https://babeljs.io/docs/usage/polyfill/ https://babeljs.io/docs/usage/polyfill/

Notice: It includes more than just promise. 注意:它不仅仅包括承诺。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM