获取获取在 Internet Explorer 11 中未定义?
Getting fetch is undefined in internet explorer 11?
我遇到了一个问题,我的下面的代码在 Internet Explorer 11 中说 'fetch' is undefined
。我使用的是最新的 jquery,即 jquery-3.3.1.min.js
,我什至尝试了 $.ajax
而不是 fetch
但这不起作用。任何人都可以使用下面的代码帮助我解决这个问题。它甚至可以在 ie11 中工作。非常感谢!
这是我的代码:
"use strict";
$(function () {
var myData = [];
$.get("#{request.contextPath}/JobSearchItem.xhtml", function (data) {
$("#searchTextField").autocomplete({
minLength: 2,
source: myData,
select: function select(event, ui) {
event.preventDefault();
var url = '#{request.contextPath}/index.xhtml';
var searchValue = ui.item.value;
var data = new FormData();
data.append('searchValue', searchValue);
fetch(url, {
body: data,
method: "post"
}).then(function (res) {
return res.text();
}).then(function (text) {
$('#results').append($(text).find('#textTable'));
$('#results').append($(text).find('table'));
$('#results').append($(text).find('#bestTable'));
$("#clearone").show();
});
},
response: function response(event, ui) {
if (!ui.content.length) {
var message = { value: "", label: "NO SEARCH RESULT FOUND" };
ui.content.push(message);
}
}
});
$.each(data, function (k, v) {
myData.push({
id: v.id,
label: v.label,
value: v.id
});
});
});
$("#sJobClass").change(function () {
var jobClassCd = $(this).val();
if (jobClassCd !== 0) {
var url = '#{request.contextPath}/index.xhtml';
var searchValue = $('#sJobClass').val();
var data = new FormData();
data.append('searchValue', searchValue);
fetch(url, {
body: data,
method: "post"
}).then(function (res) {
return res.text();
}).then(function (text) {
$('#results').append($(text).find('#textTable'));
$('#results').append($(text).find('table'));
$('#results').append($(text).find('#bestTable'));
$("#clearone").show();
});
};
});
});
fetch
Internet Explorer 不支持。
有关支持它的浏览器的更多信息:https://caniuse.com/#feat=fetch
尽管如果您已经在使用 jQuery,使用 jQuery 的内置请求函数(如 $.get
是有意义的,如果您想使用 fetch
在不更改代码的情况下,一种选择是简单地为 fetch
包含一个 polyfill:添加以下内容
<script src="https://cdn.polyfill.io/v2/polyfill.js?features=fetch"></script>
(或其他一些包含 Fetch 的 polyfill 脚本)到您的 HTML。
我遇到了一个问题,我的下面的代码在 Internet Explorer 11 中说 'fetch' is undefined
。我使用的是最新的 jquery,即 jquery-3.3.1.min.js
,我什至尝试了 $.ajax
而不是 fetch
但这不起作用。任何人都可以使用下面的代码帮助我解决这个问题。它甚至可以在 ie11 中工作。非常感谢!
这是我的代码:
"use strict";
$(function () {
var myData = [];
$.get("#{request.contextPath}/JobSearchItem.xhtml", function (data) {
$("#searchTextField").autocomplete({
minLength: 2,
source: myData,
select: function select(event, ui) {
event.preventDefault();
var url = '#{request.contextPath}/index.xhtml';
var searchValue = ui.item.value;
var data = new FormData();
data.append('searchValue', searchValue);
fetch(url, {
body: data,
method: "post"
}).then(function (res) {
return res.text();
}).then(function (text) {
$('#results').append($(text).find('#textTable'));
$('#results').append($(text).find('table'));
$('#results').append($(text).find('#bestTable'));
$("#clearone").show();
});
},
response: function response(event, ui) {
if (!ui.content.length) {
var message = { value: "", label: "NO SEARCH RESULT FOUND" };
ui.content.push(message);
}
}
});
$.each(data, function (k, v) {
myData.push({
id: v.id,
label: v.label,
value: v.id
});
});
});
$("#sJobClass").change(function () {
var jobClassCd = $(this).val();
if (jobClassCd !== 0) {
var url = '#{request.contextPath}/index.xhtml';
var searchValue = $('#sJobClass').val();
var data = new FormData();
data.append('searchValue', searchValue);
fetch(url, {
body: data,
method: "post"
}).then(function (res) {
return res.text();
}).then(function (text) {
$('#results').append($(text).find('#textTable'));
$('#results').append($(text).find('table'));
$('#results').append($(text).find('#bestTable'));
$("#clearone").show();
});
};
});
});
fetch
Internet Explorer 不支持。
有关支持它的浏览器的更多信息:https://caniuse.com/#feat=fetch
尽管如果您已经在使用 jQuery,使用 jQuery 的内置请求函数(如 $.get
是有意义的,如果您想使用 fetch
在不更改代码的情况下,一种选择是简单地为 fetch
包含一个 polyfill:添加以下内容
<script src="https://cdn.polyfill.io/v2/polyfill.js?features=fetch"></script>
(或其他一些包含 Fetch 的 polyfill 脚本)到您的 HTML。