I have had a similar issue when trying to use URLSearchParams when trying to make an AXIOS Post when using Internet Explorer. So its a little different from your description, but I'd like to post my resolution here just in case.
Here's my AXIOS post code from my React app that works just fine for Edge, Chrome and Firefox, but on IE it gives me the error
SCRIPT5009: URLSearchParams is undefined
:
let axiosConfig = {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
};
// Putting together the data to be passed to local servlet.
const params = new URLSearchParams();
params.append('var1', this.state.data1);
params.append('var2', this.state.data2);
var urlToPost = 'https://localhost:8080/someLocalServlet/doSomething';
var self = this;
axios.post(urlToPost, params, axiosConfig)
.then((res) => {
// Handling Response from Servlet.
console.log("AXIOS POST RESPONSE RECEIVED: ", res);
})
.catch((err) => {
// Handler exception error thrown by Servlet.
console.log("AXIOS POST ERROR: ", err);
})
To get it to work with IE I used jQuery to do the Post and used a var object instead of URLSearchParams.
The if statement below checks to see if the user is on IE :
if((navigator.userAgent.indexOf("MSIE") !== -1 ) || (!!document.documentMode === true )) { //IF IE > 10
var myObject = {
var1: this.state.data1,
var2: this.state.data2
};
var urlToPostTo = 'https://localhost:8080/someLocalServlet/doSomething';
$.post(urlToPost, myObject,
function(result) {
alert( "success" );
})
.done(function(result) {
alert( "second success" );
})
.fail(function(result) {
alert( "error" );
})
.always(function(result) {
alert( "finished" );
});
} else {
// use the AXIOS POST code above
}
To get the jQuery, I did have to do
npm install jquery
Then on top of my React file I imported the following:
import $ from 'jquery';
import { polyfill } from 'es6-promise'; polyfill();