IE does not render the output of multiple AJAX requests

Desiring an autocomplete feature for an input box that displays results in a div below it, I wrote this shortened code. It functions flawlessly on Chrome and Firefox - when searching for "Eggs" and then "Milk", their respective results appear. However, Internet Explorer (IE) only processes the initial request successfully; subsequent requests do not trigger any output.

The network analysis reveals that IE indeed sends the subsequent requests to the server with a 200 header code. Nonetheless, it fails to act upon the received data.

Just to note, jQuery cannot be utilized due to platform restrictions, but YUI3 is allowed.

/* Initializing Ajax */
function ajaxRequest(){var activexmodes=["Msxml2.XMLHTTP", Microsoft.XMLHTTP"],i;if(window.ActiveXObject){for(i=0; i<activexmodes.length; i++){try{return new ActiveXObject(activexmodes[i]);}catch(ignore){/*suppress error*/}}}else if (window.XMLHttpRequest){return new XMLHttpRequest();}else{return false;}}

/* Accessing search value */
var searchBoxObj = document.getElementById('searchBox-1'); 

/* Ajax Request Handler */
var theSearchValue;
var mygetrequest=new ajaxRequest();
mygetrequest.onreadystatechange=function(){
 if (mygetrequest.readyState==4){
  if (mygetrequest.status==200 || window.location.href.indexOf("http")==-1){
    var jsondata=JSON.parse(mygetrequest.responseText), /* retrieving result as JavaScript object */
      searchData = jsondata.searches,
      i;
    if (searchData.length > 0){
      document.getElementById('result').className = "on";
      output='<ul id="searchResults">';
      for (i=0; i < searchData.length; i++){
        /* Loop Code Implementation */
     }
     output+='</ul>';
   }
   else {
    document.getElementById('result').className = "";
   }

   document.getElementById("result").innerHTML = output;
  }
  else{
   /* alert("An error has occurred while making the request") */
  }
 }
};

/* Triggered with each key press */
var stoppedTyping;
searchBoxObj.onkeyup = function() {

    if (stoppedTyping) { clearTimeout(stoppedTyping);}
    stoppedTyping = setTimeout(function(){
      if (searchBoxObj.value.length > 2){
        theSearchValue = searchBoxObj.value;
        mygetrequest.open("GET", "/asp/lookup.asp?term="+theSearchValue, true);
        mygetrequest.send(null);
      }
    }, 200);
};

Answer №1

One approach you could try is using jQuery to manage your ajax requests and populate the result div. jQuery is designed to work across different browsers and should have proper support for Internet Explorer (IE). Keep in mind that version 2.* of jQuery will only support IE from version 8 onwards, while version 1.9.* will support IE from version 6.

$.ajax({
    type: "GET",
    url: your_url

})
    .done(function( data ) {
    var jsondata=JSON.parse(data);
    var searchData = jsondata.searches;
     if (searchData.length > 0){
      $('#result').attr("class","on"); //adding the class attribute
      output='<ul id="searchResults">';
      for (var i=0; i < searchData.length; i++){
        /* Your Loop Code Here */
     }
     output+='</ul>';
   }
   else {
    $('#result').attr("class","");
   }

$("#result").html(output); //populating the DOM with your output string

})
.fail(function() {
    alert( "error" );
  })

For more information, refer to the jQuery documentation: https://api.jquery.com/jQuery.ajax/

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible to utilize the same Context in multiple forms within React?

Is it possible to utilize React Context to store the state of multiple forms, or should each form have its own unique Context? Below is a snippet of code that showcases the use of React Hooks API: In FormContext.js ... import {FormReducer} from './ ...

Tips for centering a div horizontally when it exceeds the width of a mobile screen

My challenge is to create a circular div element that is wider than the mobile screen and perfectly centered. This circular div needs to be an exact circle, specifically targeted for mobile screens. I've attempted to achieve this using the code in th ...

Issue with inheritance from Angular ModalCtrl to ServiceCtrl not functioning as expected

I've been working on linking models to services in order to update global models throughout my app, but it doesn't seem to be functioning as expected. Recently, I delved into AngularJS and I suspect that I may have misunderstood my code. From wh ...

Trouble altering an attribute using jquery

Hey there, I'm struggling with changing the attribute for an id and can't quite pinpoint where I'm going wrong. It's not making things easier that I'm pretty new to this whole thing as well. I've created a function to ensure ...

Working towards ensuring my website is responsive

Hello, I am a CSS beginner currently working as an intern. My task is to make a website's CSS compatible with Internet Explorer, and then make it responsive and scalable. Essentially, the design should retain its appearance when the window size change ...

Utilize jQuery to extract all values from the second cell of a table and store them in an array

I have a task that involves pushing numbers from text boxes into an array. These text boxes are located in the second cell of each table row, while the third cell contains a date picker. Currently, the code snippet provided retrieves all values from both ...

Closing a live search box by tapping away from it

The link I found as the best example for this topic is: http://www.example.com In the example provided, if you enter a keyword in the search field, suggestions will drop down. I have implemented this code but would like to make a slight modification. I w ...

Issue with checkboxes preventing submission of form

Currently working on a website project for a company that requires certain steps to be completed for deliveries. Unfortunately, I am facing issues with the submit button, and I apologize as I am still new to this. The code I have pasted is divided into tw ...

The element you are trying to interact with is currently not visible, therefore it cannot be accessed

Currently, I am working on a small Test Automation project using C# with Selenium WebDriver. I have run into an issue where some WebElements are not visible or have their 'Displayed' property set to 'false'. This prevents me from perfor ...

Having trouble with the installation of nodemon globally on macOS Mojave?

When using the Visual Studio Code terminal, I ran the following command: npm install -g nodemon The output in the terminal showed: npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules npm ERR! code EACCES npm ERR! syscall access n ...

Having trouble with loading a new page on an HTML website

My website is successfully updating the database, printing all values, but for some reason the new page is not opening. The current page just keeps refreshing and I'm receiving a status of 0. Below is my code snippet: try{ console.log("here1 "+e ...

When using jQuery without $.ajax, the combination of $.POST and json functions will return "null" when retrieving data from PHP's json_encode

Although I am writing for the first time, I have been a part of this community before. I decided to post my query here because none of the similar questions seemed to offer a clear solution to my specific issue. I am currently working on a tic-tac-toe gam ...

Can you explain the distinction between using destructuring syntax and an empty parameter when calling a render function?

After writing some code in React, I found using this.props to be too verbose. So, I researched some articles and learned how to approach this issue while coding. class MyComponent extends Component { // the traditional method render() { re ...

Acquire Category Permissions when making a channel in discord.js v14

I am in the process of setting up a channel that will grant specific roles access while automatically blocking out @everyone. I also want this setup to be compatible with categories, allowing for other roles to have permissions within them. let customPermi ...

Leveraging JS Variables within Twig Template

I am trying to incorporate a JavaScript variable into Twig. Despite attempting to implement the solution mentioned here, my code below does not render the map properly. If I remove the part between "var polylineCoordinates" and "polyline.setMap(map);", th ...

File reading and processing must be completed before attempting to write to a new file. This is a promise-related stipulation

Feeling completely lost and stuck in a rut. Promises seemed straightforward until I actually tried to implement them. Sharing my basic code here without any promise attempts for simplicity's sake. After taking a few months hiatus from this, I returned ...

What are the Functions of Ctrl-K on Stack Overflow?

I'm intrigued by how to incorporate the Ctrl+K (code sample) feature for code. For example: public static void main(String args[]){ System.out.println.out("welcome"); } Is there a way to nicely format this? Do we need any specific package to ...

AngularJS - how to dynamically delete a directive from an element

Looking for a way to dynamically add or remove directives from compiled and linked elements? I have a page with numerous inputs and want to disable all of them if a specific flag is set. The conventional method using jQuery's element.prop('disabl ...

An issue occurred while serializing or deserializing, specifically with the JavaScriptSerializer and

I am facing an issue while trying to retrieve images from my database. The process works smoothly with small images, but when attempting to do the same with the default Windows 7 images (Desert, Koala, Penguins, Tulips, etc.), I encounter an error: "Err ...

What is the best way to convert a date to ISO 8601 format using JavaScript? Are there any built-in functions or methods in

Currently, I am using this function to set the duration: const setDuration = () => { const currentDate = new Date(); const newDate = new Date(currentDate.getTime()); const year = newDate.getUTCFullYear(); const m ...