Error encountered in Internet Explorer 11 - Access is forbidden - XMLHttpRequest

I am encountering a unique issue with IE11 and ajax. Most of the time, everything works as expected when I use the code below for my requests. However, I have noticed that when I try to use it in combination with a copy and paste function, an 'Access is denied' error is returned. To summarize:

  • This code functions normally in the majority of browsers for all the functions I have created
  • In IE 11 + Windows 8.1, it works well except when running a specific copy and paste function
  • Interestingly, even when using IE 11 with different Document modes such as 8, I still encounter the same error, despite working fine on IE8 + Windows 7
  • The error message displayed is 'Access is denied'

Here is the AJAX script:

function ajaxRequest(requestName,responseFunction,parameters) {
 var xmlhttp;
 if (requestName.length==0) return;
 if (window.XMLHttpRequest)  {
     xmlhttp=new XMLHttpRequest();
 } else {
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
 }
 xmlhttp.onreadystatechange=function() {
     if (xmlhttp.readyState==4 && xmlhttp.status==200) {
        if(xmlhttp.responseText == 'Error') alert('Error processing request. Please refresh the page and try again');
        else if(xmlhttp.responseText != '') eval(responseFunction+"('"+xmlhttp.responseText+"')");
     }
 }
 var now = new Date();
 var url = "control/ajax.php?request="+requestName+"&parameters="+parameters+"&timestamp"+now;
 xmlhttp.open("GET",url,true);
 xmlhttp.send();
}

An instance of failure occurred with the following variables set:

requestName: "save_marksheet_mark" responseFunction: "update_save_marksheet_mark" parameters: [60962,1284,5]

Is there any issue with this code? Why would IE11 specifically throw an error under certain circumstances?

Answer №1

With the high number of views on this question, I thought it might be helpful to share my solution. To resolve the issue, I implemented a setTimeout() function within the original AJAX call like so:

setTimeout(function() {
        ajaxRequest('save_progress','completed_save',[84725,2009,3]) 
    }, 1);

This quick fix did the trick, especially for those pesky bugs in IE. It just took 1 millisecond!

Answer №2

setTimeout(function() {
        ajaxRequest('save_mark','save_mark_completed',[60962,1284,5]) 
    }, 1);

Initially, this code successfully saved the mark after the page loaded. However, subsequent calls resulted in an "Access is denied" error.

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 there a way to determine the directory from which a script is being called?

Currently, I have a script specified in my package.json file as follows: "generate": "node generators/index.js". When I run npm run generate, this script is executed. The script generates a copy of a template folder located at the root of my project. Howe ...

Tips for making sure custom fonts are loaded before running any JavaScript code

Upon loading my page, I run a JavaScript function to determine if specific text fits within its parent div. If it doesn't fit, then adjustments must be made. The text is styled with a custom font, which can be loaded either through @font-face or Goog ...

Removing multiple tables simultaneously and encountering an error while utilizing ajax response text

I am facing a couple of challenges. First Issue: I encountered a problem while trying to delete groups from two tables in the database (gmembers and groups). My goal was to check if a user left a group, and if there are no remaining members in that g ...

Rotating through elements in timed intervals

After exploring various examples of how to show/hide divs with a JavaScript timeout, I am still unable to resolve my specific issue. I currently have six divs that I want to cycle through sequentially every 10 seconds, starting with div #one. Although my ...

Are ajax responses cached by contemporary web browsers?

Recently, I've discovered that we are using Cache-Control:no-cache in all of our WebApi responses. In the past, browser caching was unreliable and there was uncertainty about whether a browser would cache JSON data, hence the importance of this header ...

Vue JS console displays an error stating "the <li> tag is missing a closing tag."

Below is the code snippet I am currently using to change the color based on the character's name: I encountered an error indicating that the li tag was not properly closed, although it appears to be closed. However, there seems to be an issue during ...

Change the file name using django's ajax uploader

Currently, I am utilizing a file uploader called django-ajax-uploader in my Django project. The file uploading functionality is working fine; however, I am interested in renaming the uploaded files during the process. Specifically, I would like to include ...

BroccoliMergeTrees function encountered an unexpected data type while attempting to merge trees: TreeMerger (lint) was expecting a Broccoli node, but received an [object

Since switching to Ubuntu 18.04, I've been trying to set up my Ember development environment but have encountered an issue. While my ember project works fine on Windows, I'm getting the error "BroccoliMergeTrees (TreeMerger (lint)): Expected Broc ...

Tips for nesting maps in React without causing redundant renders

I have a list of all the items in the array let products = [ { name: "iPhone 12", storage: "64GB" }, { name: "iPhone 12 Pro", storage: "256GB" }, { name: "iPhone 12 Pro Max", storage: "512GB" ...

Encountering an error with NextJs & Strapi when utilizing the getStaticPaths functionality

Currently, my project involves using Strapi to develop a custom API and NextJs for the frontend. I am experimenting with utilizing getStaticPaths to generate pages based on different categories. In Strapi, I have set up a collection for categories that is ...

Can anyone recommend a reliable JavaScript library for creating resizable elements?

I am looking to incorporate resizable functionality for a textarea. While I have experimented with jQuery UI's "resizable" feature, it doesn't quite meet my needs. I appreciate jQuery, but the resizable option falls short in allowing me to resize ...

Issue encountered with create-next-app during server launch

Encountering an error when attempting to boot immediately after using create-next-app. Opted for typescript with eslint, but still facing issues. Attempted without typescript, updated create-next-app, and reinstalled dependencies - unfortunately, the prob ...

Combining numerous objects into one object within an array, each with distinct keys, and displaying them using FlatList

I'm struggling to present this information in a FlatList. Array [ Object { "-N1gqvHXUi2LLGdtIumv": Object { "Message": "Aeaaeaea", "Message_CreatedAt": 1652167522975, "Message_by_Ema ...

Updating Tailwind CSS to accommodate older web browsers by converting modern rgba() notation to be browser-compatible

I am facing a challenge with Tailwind CSS v3+ as it builds colors into the rgb space/color notation that is not compatible with an older browser (Safari 11) that my web app now needs to support. For example, rgb(163 160 158 / var(--tw-bg-opacity) The iss ...

Utilize the fetch function to showcase information retrieved from a specific endpoint on a webpage using Javascript

Hey there, I have a Node server with an http://localhost:3000/community endpoint. When I make a GET request to this endpoint, it returns information about three different users in the form of JSON objects. [ { "avatar": "http://localhost:3000/avatars ...

Sending data from an external input field to a form using AngularJS programmatically with element name

I am facing a challenge where I need to include an Input element in a Form, even though the Input is located outside of the form. While I have managed to add the input using form.$addControl(outerInput), it is not producing the desired outcome as shown in ...

Injection of Angular state resolve into controller fails to occur

I'm attempting to ensure that the value from ui-router's resolve is successfully passed to the controller portalsForUserCtrl. Take a look at the router code below: (function () { 'use strict'; var myApp = angular.module("myApp", ["co ...

Trouble with implementing web methods through AJAX communication channel

my .cs code is auth_reg.aspx.cs (breakpoint shows the method is never reached) [WebMethod] public void ImageButton1_Click() { string strScript = "<script language='JavaScript'>alert('working')</script>"; Page.Regis ...

Node js - Looping Through Loading

I am facing an issue with my Node.js application. It runs perfectly fine on my local environment, but when I try to run it on my server using forever, the page just keeps loading without displaying anything. There seems to be no response and it gets stuc ...

Tips for resolving Ajax post issue related to removing leading zeros

Trying to transfer a value from one page to another via modal, but facing an issue. When attempting to document.write the passed value, it shows up as 0 instead of 0003. On the First Page: <button onclick="openmodalseparationpay(<?=$row['EmpN ...