rahulrautwar
rahulrautwar

Reputation: 76

How to post data URLSearchParams With Fetch in IE 11

When I am trying to post bodydata using URLSearchParams in fetch, its working in Chrome v72 and Edge v40 but not on IE11 (with polyfills).

On IE11: I am getting this error:

Error: unsupported BodyInit type

I am using the following polyfills for Edge/IE/etc browsers:

Upvotes: 0

Views: 2121

Answers (1)

Sh4m
Sh4m

Reputation: 1532

You can use below

Example your request body

{..., body : objToBodyObj(obj) ..}

Below is function

function objToBodyObj(obj) {
  var str = "";
  for (var key in obj) {
    if (str != "") {
      str += "&";
    }
    str += key + "=" + encodeURIComponent(obj[key]);
  }
  return str;
}

Upvotes: 0

Related Questions