I have some Problem with this code. I will use this code instead of a polyfill. The code works using Firefox, Chrome, Opera and MS Edge but the Internet Explorer 11 is not responding. Can someone give me a tip for Troubleshooting.
function fetchFile(file,method,params,target) {
const controller = new AbortController();
const signal = controller.signal;
setTimeout(controller.abort.bind(controller), 5000);
var options = { method: method, signal };
if (params != 'default') {
switch (method) { case 'GET': file = file+'?'+params; break;
case 'POST': var data = params; break; default: data = 'data'; break;}
}
switch (method) { case 'POST': options.body = data; options.headers = {"Content-Type": "application/x-www-form-urlencoded"}; break;}
fetch(file, options).then(function (response) {
return response.text();
}).then(function (data) {
document.getElementById(target).innerHTML = data;
switch (data) {case '': loadXhttp(file,method,params,target); break;}
}).catch(function (data) {
switch (error.name) {
case 'AbortError': var error = 'Abort Error'; break;
default: error = 'Other Error'; break;}
document.write(error);
});
}
function loadXhttp(file,method,params,target) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById(target).innerHTML = this.responseText;
}
};
xhttp.open(method, file, true);
switch (method) {case 'GET': var send = null; break;
case 'POST': xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
send = params; break;}
xhttp.send(send);
}
I would recommend looking into isomorphic fetch
On request, here is how you would use it
Install the isomorphic-fetch
and es6-promise
packages
npm install --save isomorphic-fetch es6-promise
After you have installed the packages, require
them in your application
require('es6-promise').polyfill()
require('isomorphic-fetch')
This should allow you to use fetch
normally
fetch(url).then(handleResponse).catch(handleError)
i have used isomorphic fetch and it works fine in all browsers
require('es6-promise').polyfill();
require('isomorphic-fetch');
For any folks finding this after failing to get Netlify's stateful React app form submit to work properly in IE 11 - (the form updates the URI bar but does not actually submit) - this is your answer!
npm install --save isomorphic-fetch es6-promise
On the first loading JS file (index.js in my case) add:
import "es6-promise";
import "isomorphic-fetch";
The submit should now go through.
(If you can't even get IE 11 to render your React app at all go ahead and "npm install babel-polyfill" and make importing it the very first line in your first loaded JS file).
I need to have something similar to Facebook Messenger's chat heads in my app, basically a bubble that can be viewed over other apps. I can't find anything online on this topic besides this question. ...
I need to have something similar to Facebook Messenger's chat heads in my app, basically a bubble that can be viewed over other apps. I can't find anything online on this topic besides this question. ...
There will be for sure a duplicate for this question, but I'd like to have an answer for this specific piece of code. I have this function: var somevar = ""; some.method({ ... }).then(function (...
There will be for sure a duplicate for this question, but I'd like to have an answer for this specific piece of code. I have this function: var somevar = ""; some.method({ ... }).then(function (...
I fail to parse the first query string parameter using the qs npm package. What am I doing wrong? I execute these commands in my console import * as qs from './qs' var addr = "https://www.somesite....
I fail to parse the first query string parameter using the qs npm package. What am I doing wrong? I execute these commands in my console import * as qs from './qs' var addr = "https://www.somesite....
I am trying to add some custom color in the material design base templates, module.js var app = angular.module('AppTool', ['ngMaterial', 'ui.router', 'ngCookies', 'ngResource','ngRoute', 'satellizer'...
I am trying to add some custom color in the material design base templates, module.js var app = angular.module('AppTool', ['ngMaterial', 'ui.router', 'ngCookies', 'ngResource','ngRoute', 'satellizer'...