gpt4 book ai didi

javascript - 获取 fetch 在 Internet Explorer 11 中未定义?

转载 作者:行者123 更新时间:2023-11-28 12:13:57 28 4
gpt4 key购买 nike

我遇到一个问题,下面的代码显示 Internet Explorer 11 中的 'fetch' 未定义。我使用的是最新的 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();
});
};
});


});

最佳答案

尽管如果您已经在使用 jQuery,那么使用 jQuery 的内置请求函数(如 $.get)是有意义的,如果您想使用 fetch 而无需使用更改您的代码,一种选择是简单地包含用于fetchpolyfill:添加以下内容

<script src="https://cdn.polyfill.io/v2/polyfill.js?features=fetch"></script>

(或其他一些包含 Fetch 的 polyfill 脚本)到您的 HTML。

关于javascript - 获取 fetch 在 Internet Explorer 11 中未定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54139803/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com