我遇到一个问题,下面的代码在Internet Explorer 11中说'fetch' is undefined
。我使用的是最新的jquery-3.3.1.min.js
jQuery,甚至尝试了$.ajax
而不是fetch
,但是没有用。任何人都可以通过下面的代码帮助我解决此问题。它甚至可以在ie11中工作。非常感谢你!
当我使用$_ajax
而不是fetch
时,出现控制台错误,提示res.text is not a function TypeError: res.text is not a function
这是我的代码:
"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();
});
};
});
});
答案 0 :(得分:0)
执行此操作
<div class="flex__wrapper">
<div class="col-m-12 col-t-4">
<a class="flex__link" href="#">
<div class="flex__top">
<img src="https://placeimg.com/640/480/arch" class="flex__img">
<h2 class="flex__h2">Check back tomorrow;</h2>
<p>I will see if the book has arrived.</p>
</div>
<div class="flex__bottom">
<ul>
<li>Learn More</li>
</ul>
</div>
</a>
</div>
<div class="col-m-12 col-t-4">
<a class="flex__link" href="#">
<div class="flex__top">
<img src="https://placeimg.com/640/480/nature" class="flex__img">
<h2 class="flex__h2">I am happy</h2>
<p>I am never at home on Sundays.</p>
</div>
<div class="flex__bottom">
<ul>
<li>Learn More</li>
<li>Progressively matrix</li>
<li>Uniquely build extensible</li>
<li>seamless customer</li>
</ul>
</div>
</a>
</div>
<div class="col-m-12 col-t-4">
<a class="flex__link" href="#">
<div class="flex__top">
<img src="https://placeimg.com/640/480/people" class="flex__img">
<h2 class="flex__h2">Malls are great places to shop</h2>
<p>I can find everything I need under one roof.</p>
</div>
<div class="flex__bottom">
<ul>
<li>maximizing</li>
<li>Monotonectally whiteboard</li>
</ul>
</div>
</a>
</div>
<div class="col-m-12 col-t-4">
<a class="flex__link" href="#">
<div class="flex__top">
<img src="https://placeimg.com/640/480/tech" class="flex__img">
<h2 class="flex__h2">I want to buy</h2>
<p>but know it won’t suit me.</p>
</div>
<div class="flex__bottom">
<ul>
<li>Learn More</li>
<li>task error-free</li>
<li>Energistically</li>
<li>practices</li>
<li>ethical methodologies</li>
<li>task error-free</li>
</ul>
</div>
</a>
</div>
<div class="col-m-12 col-t-4">
<a class="flex__link" href="#">
<div class="flex__top">
<img src="https://placeimg.com/640/480/animals" class="flex__img">
<h2 class="flex__h2">Last Friday in three week</h2>
<p>Blue worm shake hands with a legless lizard.</p>
</div>
<div class="flex__bottom">
<ul>
<li>Learn More</li>
<li>incubate</li>
</ul>
</div>
</a>
</div>
<div class="col-m-12 col-t-4">
<a class="flex__link" href="#">
<div class="flex__top">
<img src="https://placeimg.com/640/480/animals/grayscale" class="flex__img">
<h2 class="flex__h2">She advised</h2>
<p>him to come back at once.</p>
</div>
<div class="flex__bottom">
<ul>
<li>Learn More</li>
<li>Seamlessly</li>
<li>build excellent</li>
</ul>
</div>
</a>
</div>
</div>
将其导入您的代码中并使用。