Is the XMLHttpRequest.onreadystatechange event still triggered behind the scenes when Promises are utilized?

Imagine I am utilizing a Promisified API for executing an Ajax Request, would the event-loop still resort to calling the basic

XMLHttpRequest.onreadystatechange
?

Although using Promisfying enables coding in a sequential manner, essentially it is still relying on the traditional mechanisms behind the scenes. It's somewhat akin to the utilization of the class syntax in ECMASCRIPT 6. Ultimately, are the core API's remaining unchanged?

I'm struggling to comprehend how we could directly link a Promise with an event-loop, as there needs to be some sort of logic in place that can "resolve" or "reject", necessitating a simple wrapper [which could potentially be implemented as a promise, although it might result in an excess of promises]?

Answer №1

Suppose I am utilizing a Promisified API to make an Ajax Request, would the event-loop still trigger the traditional XMLHttpRequest.onreadystatechange?

There are various methods for making Ajax requests.

A library that encapsulates a promise around XHR could potentially utilize the readystatechange event. It might also employ load and error events.

A promise-based Ajax library could bypass XHR altogether.

It might opt for JSONP.

The fetch method is natively supported in browsers, operates using promises, and doesn't interact with XHR.

Is this similar to the class syntax in ECMASCRIPT 6? Basically, are the core APIs unchanged?

No.

Promises represent a standardized API, not merely a different way to execute the same tasks as current code.

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

How can I attach a jQuery plugin to a textbox with a changing class name?

I have a function that converts a regular text field into a datepicker: <input type="text" class="datepicker form-control" name="text-150" > var DatePicker = function () { if ($(".datepicker").length === 0) { return; } $(".datepic ...

What are the steps to kick off my React App once I've cloned it?

Currently grappling with deploying my app using Netlify, I encountered an issue after cloning the app onto my new computer. > <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8afee5eee5e6e3f9fefcb8cabba4baa4ba">[email  ...

What is the best method for updating inner html with AJAX using the results obtained from json_encode?

If you need further clarification on how this works, feel free to check out this fiddle for a demonstration. In my setup, I have multiple DIVs each with a unique ID such as desk_85 (the number changes accordingly). <div class="desk_box_ver id="desk_8 ...

html carousel not updating in popover

I've been attempting to create a popover with a bootstrap carousel, where the carousel items are dynamically generated and appended from a script. Despite my efforts, I have successfully displayed the carousel but struggle to append the items. I' ...

Exploring the JSON object and dynamically incorporating elements into it is my goal as I navigate through AngularJS

I'm seeking a way to display the entire JSON data in a tabular format, with the ability to dynamically loop through any additional values that are added. Here is an example of my current JSON: $scope.tableContent = [ { id: 1, ...

What are the most effective methods for organizing a substantial redux project?

After recently diving into Redux, I've been enjoying the process so far. However, as my application continues to expand, I find myself questioning the best practices for structuring it. The tutorials and documentation provide small examples, leaving m ...

Different kinds of functions can take an optional property name as an argument and either return the value of that property in an object or the entire object itself

In need of a function that accepts an optional parameter propName, which must be a key belonging to SOME_OBJECT. The function should return the value of propName if it is provided, or else return the entire OBJECT: Here's the code snippet: type SOME_ ...

Node's Input Standardization

While I have been delving into the basics of JS and coding in Sublime, I recently made the transition to VSCode. This shift has left me feeling somewhat lost as I attempt to find alternatives to using prompt(). My previous coding method looked like this: ...

Error in Vue: Trying to set a property ('message') on an undefined object

As a newcomer to Vue.js, there are some concepts that I may be overlooking. Despite working on it for months, I have been unable to find a solution. My goal is to change the message displayed in a v-alert by using a separate JavaScript script to import the ...

Access the .net web api from a different computer

Currently, I am working on a project that requires me to create a REST API for clients. This API will retrieve data from a database and return it in JSON format. Below is the code for my controller: [Models.AllowCors] public HttpResponseMessage Ge ...

Creating a dynamic HIIT program with an autoplay feature for videos and images, using a jQuery/JavaScript slider "playlist" with the backend support of

I am currently exploring the idea of developing a countdown timer that incorporates videos. In order for this timer to function effectively, it must be able to retrieve data such as countdown time, break time, number of sets, and video (or images if no vid ...

Converting JSON data to JavaScript using AJAX and PHP

Utilizing JavaScript coupled with AJAX enables the display of additional information when a user chooses a 'deal_name' from the dropdown menu using the showPartnerInfo function. The following excerpt from the k1.php file is pertinent: function s ...

Why is the JSfiddle tutorial not functioning properly in other environments, generating the error "Property 'clientHeight' cannot be read of null"?

I've been diving into a THREE.js tutorial to learn how to set up a basic scene and add animation keyframes triggered by scrolling. Everything worked smoothly in the fiddle, but when I tried to transfer it to my website, I encountered this persistent e ...

Reactstrap and React-router v4 are failing to redirect when there is a partial change in the address link

Within the header of my website, <NavItem> <NavLink tag={Link} to="/template/editor">Create New Template</NavLink> </NavItem> On the routing page of my website, <BrowserRouter> <div className="container-fluid"> ...

In my handleSubmit function, I'm attempting to prevent my browser from refreshing whenever I send a Post request to the backend

I am encountering an issue with my form where my submit button triggers a handleClick event. When the handleSubmit function is executed, a Post request is made to the backend to update the data and state. However, this action results in the entire page bei ...

Can someone explain the process of unescaping characters in an API response to me?

I have created an application that leverages AngularJS to pull data from the WP Rest API V2. The response includes escaped characters, like the example below: "excerpt": { "rendered": "<p>When we go shopping, we encounter many different labeling ...

Parent function variable cannot be updated within a $.ajax call

I'm facing an issue with pushing a value from inside an ajax call to an array located outside of the call but still within the parent function. It appears that I am unable to access or update any variable from inside the ajax success statement. Any as ...

"Unexpectedly, the original values of an array were altered by a Javascript

After creating a constructor function to generate an object, I set up an array named arr1 with initial values. Next, I use the map function on arr1 to create a new array called arr2. However, I noticed that the original arr1 was altered. Could this be du ...

Receiving 'Unexpected end of input' error when using a string as a JavaScript function argument

I am trying to implement an ajax request function in my project. This is the code snippet I have: function Reject(id, scomment) { jQuery.ajax({ type: "POST", url: "reject.php", data: {id: id, Scomment: scom ...

What advantages does using extend in the prototype offer in the inheritance pattern of three.js?

While delving into the world of Three.js framework and in search of an efficient JavaScript inheritance pattern, I decided to explore how it was implemented in Three.js itself. After studying it closely, I have gained a solid understanding of most aspects, ...