0

I've created a small search function that will go through a bunch of XML data and pull out results based on the user's query, it works swimmingly in Chrome but it consistently crashes IE11 after the user enters about two characters.

Before you ask, I am using a prototype for .filter copied directly from MDN. I didn't include this because it works and doing so would have doubled the length of the code.

    function search() {
      var query = document.getElementById("query").value.toLowerCase();
      returnSearch(query);
    };

    //loads xml data
    function loadData() {
      var data = new XMLHttpRequest();
      data.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
          getData(this);

        }
      };
      data.open("GET", "abbreviations.xml", true);
      data.send();
    };

    function getData(xml){
      var xmlDoc = xml.responseXML;
      var acronym = xmlDoc.getElementsByTagName("acronym");
      for(var i=0; i < acronym.length; i++) {


        content.push(acronym[i].getElementsByTagName("name")[0].childNodes[0].nodeValue + " means: "+ acronym[i].getElementsByTagName("meaning")[0].childNodes[0].nodeValue );
      }
    };
    function returnSearch(query) {
      var regexp = new RegExp(query, 'i');

      //Its laughable that ie dosen't accept arrow functions
      var results = content.filter(function (result) {
        return regexp.test(result);
      });



      document.getElementById('results').innerHTML = results;
      console.log(results);
    };

This works fine in Chrome, so my question is less of a how to and more of a "why does IE not like this".

tfantina
  • 788
  • 11
  • 37
  • 1
    any console errors? – Naga Sai A Apr 11 '18 at 20:06
  • No errors, but the page gets hung up, possibly before it has the time to produce an error. When the page loads it does say "The attached page targets document mode 5. Some APIs and features may not be available." But I'm not sure if that would be related to my problem. – tfantina Apr 11 '18 at 20:26
  • Try calling `open` before installing `onreadystatechange`. – Bergi Apr 11 '18 at 20:37
  • _"The attached page targets document mode 5"_. What does your page's DOCTYPE look like? ([might be an explanation](https://msdn.microsoft.com/en-us/library/ff955379(v=vs.85).aspx)) – blex Apr 11 '18 at 20:50
  • I ended up using the answer [here](https://stackoverflow.com/questions/3449286/force-ie-compatibility-mode-off-using-tags) changing content to `"IE-Edge"` in the meta tag. – tfantina Apr 12 '18 at 14:13

1 Answers1

0

Essentially I ended up using a meta tag to force IE to "Edge" mode. IE is so finicky it's always a good idea to play around with this content tag if something is not working however according to Microsoft you may encounter issues if you do this in production.

This question answered mine: Force IE compatibility mode off using tags

as well as this article from MDN META Tags and Locking in Future Compatibility

tfantina
  • 788
  • 11
  • 37