The malfunctioning of my Ajax functionality is causing issues

Today, I delved into the world of Ajax. I took the time to practice and follow step-by-step instructions on how to use AJAX, but unfortunately, I encountered an issue. I couldn't pinpoint the problem as there were no warnings displayed in the console.log.

Within my root folder, there lies an example.xml file from which I attempted to retrieve data.

Here's a summary of my process. Any assistance would be greatly appreciated!

function settingXMLHttpRequest(){
var request = null;
    
    if(window.XMLHttpRequest || window.ActiveXObject){
    if(window.ActiveXobject){
        try{
            request = new ActiveXObject("Msxml2.XMLHTTP");
            }catch(e){
            request = new ActiveXObject("Microsoft.XMLHTTP");
            }
        }else{
        request = new XMLHttpRequest();
        }
    
    }else{
    alert("The XMLHttpRequest object is not supported by your browser");
    }
    
    return request;
}


function sendRequest(callback){

var request = settingXMLHttpRequest();
    
    request.onreadystatechange = function(){
    if(request.readyStae == 4 && (request.status == 200 || request.status == 0)){
        callback(request.responseBlob);
        }
    }
    
    request.open("GET", "example.xml", true);
    request.send(null);    
}

    function processData(data){
    var node = data.getElementsByTagName("soft");
        var unorderedList = document.createElement("ul");
        var listItem, itemContent;
        
        for(let i = 0; i < node.length; i++){
        
        listItem = document.createElement("li");      
           itemContent = document.createTextNode(node[i].getAttribute("name"));
            listItem.appendChild(itemContent);
            unorderedList.appendChild(listItem);
        }

        document.getElementById("output").appendChild(unorderedList);
    }
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8>
<title>ajax</title>
</head>
<body>
<p>
<button onclick="sendRequest(processData);">Display data</button>
</p>
<div id="output">

</div>
</body>
</html>

Answer №1

Your code contains a small error.

xhr.onreadystatechange = function(){
        if(xhr.readyStae == 4 && (xhr.status == 200 || xhr.status == 0)){
            callback(xhr.responseXML);
        }
}

The correct syntax is xhr.readyState == 4, not xhr.readyStae == 4.

xhr.onreadystatechange = function(){
        if(xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)){
            callback(xhr.responseXML);
        }
}

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 is the best way to access the rendered child components within a parent component?

I am seeking a way to retrieve only the visible child components within a parent component. Below is my unsuccessful pseudo-code attempt: parent.component.html <parent (click)="changeVisibility()"> <child *ngIf="visible1"></child> ...

Creating dependent dropdowns using Laravel Inertia Vue: A step-by-step guide

In my AddressController, I have a function called loadCity along with other CRUD functions: public function loadCities(Request $request) { $provinceId = $request->province_id; $cities = Province::where('province_id' ...

What is the best way to activate Cropper once a file has been selected, without encountering a 404 error on the image?

I've been trying to integrate an image cropper into my website, but I'm encountering some issues that I can't seem to resolve. Expected outcome : Upon selecting a picture from the disk using the file input, a modal should appear prompting t ...

What are the steps to create a ListView in a ChatApp for organizing and viewing all conversations?

In developing my chat application, I am considering using a List to organize all the chats. Since my app is integrated with Firebase, I am faced with the decision of whether to utilize a FlatList and store all data locally or in a Firebase database. What ...

Creating a universal header for all webpages in Angular JS by dynamically adding elements using JavaScript DOM manipulation techniques

I have successfully created a json File containing an array of "learnobjects", each including an id, name, and link. Check out my plnkr example var myMessage = { "learnobjects": [{ "id": "1", "name": "Animation-Basics", "link": "animation_bas ...

Receiving CORS response from the server for just one of the two API calls

Description of the issue: I am facing a peculiar problem where I am encountering different responses while making two calls to the same API. One call is successful, but the other returns a 504 error. Access to XMLHttpRequest at '' from orig ...

Guide to modifying the column color in Chart.js

Link to my codepen project: Check it out here let ctx = document.getElementById('myChart').getContext('2d'); let chart = new Chart(ctx, { // Type of chart being created type: 'bar', // Data for the dataset data: { ...

What is the best way to stop a jQuery function from applying titles extracted from the first row th's in thead's to multiple tables in a document?

My circumstances: I am new to jQuery and Stack Overflow, seeking assistance for my website project. The challenge: Building a website using Bootstrap 3.3.6 with intricate data tables that need to be stacked dynamically on mobile devices using CSS. It is c ...

Is there a way to send a personalized reply from an XMLHttpRequest?

My goal is to extract symbol names from a stocks API and compare them with the symbol entered in an HTML input field. I am aiming to receive a simple boolean value indicating whether the symbol was found or not, which I have implemented within the request. ...

Sending data from an Angular application using AJAX to FormSpree.io

Currently, I am using a jQuery script to send ajax requests to for static form submission. The documentation provided by FormSpree suggests the following approach: $.ajax({ url: "//formspree.io/<a href="/cdn-cgi/l/email-protection" class="__cf_email ...

What is the technical process behind conducting A/B testing at Optimizely?

I'm currently experimenting with Google Analytics and Content Experiments for A/B testing on my website, but I'm encountering some challenges in making it seamless. To utilize the Google API properly, a few steps need to be taken. Firstly, I nee ...

Eliminating an element from an array depending on the value of its properties

I need to remove an object from my List array by matching its properties value with the event target ID. Currently, I am using findIndex method to locate the index ID that matches the event.target.id. Below is an example of one of the objects in my list a ...

Using jQuery to send JSON data through AJAX to PHP

I'm attempting to utilize jQuery AJAX to send JSON data to a PHP file. My goal is to extract the values and IDs from multiple child elements, create a JSON object with this data, and then transmit that object to a PHP file for processing and insertion ...

"Performing a row count retrieval after updating records in a Microsoft SQL Server database

Recently, I have been utilizing the MSSQL NodeJS package (https://npmjs.org/package/mssql#cfg-node-tds) in order to establish a connection with a MS SQL database and execute UPDATE queries. One thing that has caught my attention is that when an UPDATE que ...

Installing Vue JavaScript using the npm command

Embarking on my journey as a Vue JS learner, I took the plunge to install Vue and delve into creating web applications using it. So, I globally added npm Vue. npm install --global vue-cli This action resulted in: npm WARN deprecated [email protected]: T ...

I am having trouble retrieving the array value from the response sent by my server

After receiving a dictionary from my server, when I try to access the values using the following code: {"filters":{ "Facture": [ "Магма (Тычок)", "Тонкий кирпич", "Гладк ...

Effortlessly sending information to the Material UI 'Table' element within a ReactJS application

I have integrated a materialUI built-in component to display data on my website. While the code closely resembles examples from the MaterialUI API site, I have customized it for my specific use case with five labeled columns. You can view my code below: h ...

Ways to create a back-and-forth transition across a sequence

Is it possible to create an animation that changes the width of an element once, then reverts back after a pause? I want this transition to occur over a three-second interval followed by a two-second delay. How can I achieve this? Below is the code I have ...

Interactive Requirement 6 UpdatePanel Requires Manual Mouse Movement for Refresh Post-Asynchronous Call

Our team is currently confined to using IE6 and unable to switch to a different browser. We've encountered an issue in our application where, after a postback occurs within our updatepanel, the browser appears to be resetting the DOM. One select box s ...

Having two identical select2 forms on the same page

Integrating two select2 multi-value select boxes into my Rails application is proving to be a challenge. While the top form functions correctly, the bottom one refuses to work as expected. Despite my attempts at changing IDs and adding new JavaScript cod ...