简体   繁体   English

如何修复“提取”在IE11中未定义?

[英]how to fix 'fetch' is undefined in ie11?

I am coming to an issue where my code below, says that 'fetch' is undefined in internet explorer 11. I am using the latest jquery which is jquery-3.3.1.min.js and I even tried $.ajax instead of fetch but that did not work. 我遇到一个问题,我的下面的代码说Internet Explorer 11中'fetch' is undefined 。我使用的是最新的jquery,即jquery-3.3.1.min.js ,甚至尝试了$.ajax而不是fetch但这没有用。 Can anyone help me solve this issue, with my code below. 任何人都可以通过以下代码帮助我解决此问题。 That it can even work in ie11. 它甚至可以在ie11中工作。 thank you very much! 非常感谢你!

when I do $_ajax instead fetch I get an console error saying res.text is not a function TypeError: res.text is not a function 当我执行$_ajax而不是fetch出现控制台错误, res.text is not a function TypeError: res.text is not a function

Here is my code: 这是我的代码:

"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();
            });
        };
    });


});

Do this- 做这个-

npm install --save isomorphic-fetch es6-promise

import it in your code and use it. 将其导入您的代码并使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM