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

What techniques does DeviantArt use to adapt and adjust the content displayed on a page based on the width of the user's

Visit and observe the functionality where new content appears as you widen your browser window. The alignment of the content in the center is a key aspect of this design on DeviantArt's website. How is this achieved? I attempted to create a div with ...

Having trouble with Vue 3 Component State not updating following an asynchronous operation?

Encountering challenges in my Vue 3 app when trying to update a component's state post an asynchronous operation. Here's what's happening: Within a component, there is a method called containerMoveHere that utilizes Socket.io for an async o ...

What is the method for striking through a line in a table?

I developed a unique jQuery script: <script type="text/javascript"> $(document).ready(function () { $('tr.inactive').each(function (index) { var tr = $(this); tr.find('td:first').after(function ...

Breaking apart web addresses and their attached parameters

I am attempting to extract the part of a URL that comes after the last forward slash (/) and before the querystring. While I have been successful in obtaining the last segment of the URL, I have encountered difficulty in removing the querystring from it. ...

Run a function upon clicking a button in JavaScript

Could someone please help me figure out what I am doing incorrectly in the code below? I am attempting to trigger a function when a button is clicked. The HTML: <button id="btn1">Press me!</button> <input type="button" id="btn2" value="Pr ...

Is there a way to detect duplicate usernames in a form without actually submitting the form, and then automatically focus on the username field if a duplicate is

I need help with a user registration form that I am creating. I want the form to automatically search for an existing username as soon as the user starts typing in the username field. If the username already exists, I want the field to receive focus. In my ...

Issues with retrieving $_POST values from a select form in PHP

When the button is clicked, I am sending a AJAX request to my PHP page using POST method with the selected data from a SELECT element. However, I am facing an issue where my PHP IF statements are not evaluating as true. It always defaults to the ELSE condi ...

AngularJS does not recognize the service being referenced

I keep encountering an error in AngularJS saying that the service is not defined, even though my controller and module are properly connected: application.js: var myapp=angular.module('myApp', []); myapp.service('productService', fun ...

Prevent automatic jumping to input fields

Can someone help me with a problem related to the html input tag or primefaces p:input? I am facing an issue where the cursor always automatically jumps into the input field. The height of my page is such that scrolling is required, and the input field i ...

employing the $.getJSON method for fetching CSV information

I've been experimenting with Yahoo's Finance API to fetch stock data: $.ajax({ dataType: "json", url: 'http://download.finance.yahoo.com/d/quotes.csv', data: 's=RHT+MSFT&f=sb2b3jk&am ...

I can't figure out why I keep receiving the InvalidArgumentError for H.Map with Argument #0 [object Object]

I recently refactored the code taken from the Maps API for JavaScript "Working with React" section. As a beginner in React and currently learning it in school, I have to utilize functional components. The material provided guidance on class component syn ...

Angular unburdened by jquery

I need help converting the following code from using JQuery to only Angular. I am unsure of how to accomplish this. Thank you! var startProduct = $("#product-overview").position().top - 60; var endProduct = $("#global-features").position().t ...

Encountered an issue while trying to set up mocks with $route in vue-test-utils

I am currently practicing test referencing by using a mock router. Here is the code I am working with: NestedRoute.vue <template> <div> <div>Nested Route</div> <div class="username"> {{ $route.params.username ...

Mastering the art of using the async pipe in conjunction with rxjs

I require assistance as the loading component of my async pipe does not activate, despite the data loading correctly. The loading template fails to trigger during subscription even though I am using a BehaviorSubject in my service. I have attempted various ...

Develop a client-side API utilizing various libraries

After completing the server side of an API that delivers HTML via JSON using REST through CodeIgniter, I am now exploring how to create a client-side API with JavaScript. The goal is to retrieve data from the server through the API, display it in the DOM, ...

"Unfortunately, the Ajax Update feature seems to only work properly on

Encountering difficulties with updating records in a PartialView using Ajax. A View is called with @Html.Action("_PartialView", "Controller", new { id = OrderId }) and a PartialView contains an Ajax Form. @model IEnumerable<WebMartin.Models.OrderExecut ...

The cart total variable in Vuejs is coming back as NaN

I'm currently in the process of creating a cart system using vuejs and I've encountered an issue where my total variable is displaying NaN instead of calculating the total price of all products. Below is the function responsible for calculating ...

Update overall font size to be 62% for a consistent look across the website

Recently, I developed a browser extension that adds an overlay button to the LinkedIn website. Everything was running smoothly until I discovered that LinkedIn uses a global font-size: 62,5% that completely messes up my design.. https://i.stack.imgur.com ...

The issue of mapping C# optional parameters with JSON data in an Ajax request, specifically when they have the same name but different types

Having trouble with the json data Parameters of an ajax request not matching properly for an optional parameter of a c# method $.ajax({ url: '/CusotmerManagement/Cusotmer/GetCusotmerByDisplayId/', ...

Using JavaScript to dynamically set a background image without the need for manual hard-coding

My attempt was to showcase images as a background image upon mouseover event for the div section with id 'message' by manually coding JavaScript functions for each image like this: Here is the HTML code inside the body section <div id = "mes ...