Safari is currently unable to process XML responses

Here is the code we have attempted, please review and provide feedback.

function GetXmlHttpObject()
{ 
    var objXMLHttp=null;
    if (window.XMLHttpRequest)
    {
        objXMLHttp=new XMLHttpRequest();
    }
    else if (window.ActiveXObject)
    {
        objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
        
    }
    return objXMLHttp;
} 


function show(url,did)
{
    divId=did;
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    if(url.indexOf("?")!=-1)
    url=url+"&sid="+Math.random();
    else
    url=url+"?sid="+Math.random();

    xmlHttp.open("GET",url,true);
    xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.send(null);

} 

function stateChanged()
{ 

    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    { 
        document.getElementById(divId).style.display='block';
        document.getElementById(divId).innerHTML=xmlHttp.responseText;
    }
}

Answer №2

Consider replacing the logical || operator with &&:

function stateChanged()
{ 
    if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
    { 
        document.getElementById(divId).style.display='block';
        document.getElementById(divId).innerHTML=xmlHttp.responseText;
    }
}

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

Using JQuery's onChange event triggers actions based on the current values of input fields. However, in some

I am currently tackling an issue with a module that is designed to automatically select the only valid value from a Multi- or Single selection field when there is just one valid option and an empty choice available. Initially, everything was working smoot ...

Optimal approach for initiating an ajax request

I am currently facing an issue with my ajax call which is wrapped into a function for polling purposes. function doPoll(){ alert('GO POLL') setTimeout(function(){ $.ajax({ 'method':'POST ...

Arrange the array in chronological order based on the month and year

I'm looking for assistance with sorting an array by month and year to display on a chart in the correct order. Array1: ['Mar19','Apr18','Jun18','Jul18','May18','Jan19'....]; Desired Output: ...

Accessing a JSON array using AngularJS

I am working with a JSON array that looks like this: [{ "id": "21390238becde1290", "chelsea": { "homeTeam": "chelsea", "sortName": "ches", "awayTeam": "Maribor", "awayShort": "" }, "barclays": { "id": "21390238becde1290", "homeTeam ...

Steps to remove a row from a table in a ReactJS component

I'm struggling with implementing a delete operation for table rows and encountering errors. Any assistance in resolving this issue would be greatly appreciated. Since I am unsure how to set an auto-incrementing id, I used Date.now(). Now my goal is t ...

Is there a way to utilize the revealing prototype pattern in JavaScript to namespace functions stored within prototypes?

Currently implementing the Revealing Prototype Pattern, I have integrated two distinct prototypes within a single JavaScript file. Here are some articles that shed light on this topic: , . My assumption was that these prototypes would function like atomic ...

Ajax will not halt until the execution of another php script is finished

Upon submitting a form filled out by the user, a new tab opens to load the results. The script then goes through multiple XML files which can take anywhere from 2-10 minutes due to the complexity of the process. To track progress on the results page, I inc ...

Guide on building a multi-page application using Vue or React

I find myself a bit confused when it comes to single-page applications versus multi-page applications. While I am aware of the difference between the two, I am struggling with creating a MPA specifically. Up until now, I have built various apps using Rea ...

Trying out REST endpoints using curl's -X PUT command results in a 404 error code

Currently, I am delving into the realm of the MEAN stack and following along with the MEAN tutorial provided by thinkster.io. You can find the tutorial here: As of now, I am navigating through the "Opening REST Routes" section. In an attempt to PUT an upv ...

If the user inputs any text, Jquery will respond accordingly; otherwise,

I have a text field that is populated from a database, but if a user decides to change the value, I need to use that new value in a calculation. $('#ecost input.ecost').keyup(function(){ if (!isNaN(this.value) && this.value.length != ...

Unable to postpone the utilization of data in Vue until after retrieving the value from the database

I am facing an issue where I need to compare a string obtained from Firebase in document.check1 with specific strings (hardcoded in the function below) and display content accordingly. Currently, I know how to trigger this comparison on button click, but I ...

combine elements from a different document using a local field as a key

I'm currently working on a project involving a competition document with a field teams array of objects containing the _id of each team, as well as a score document with a teamId field. The competitions.teams array looks like this: [{_id: 100,..}, {.. ...

Transferring form data to an external webpage and fetching the HTML response from the server

Is it possible to retrieve the HTML or plain text from the result of a form sent to an external page? I have a form that sends variables to an external server and the result goes to an iframe. How can I retrieve the HTML or text from the iframe? I'm ...

What is the best way to iterate through a JSON object in a subsequent AJAX call

Is there a way to loop through all the number channels in the JSON file? I have numerous numbers and I would like to display them one by one: alert(res.available_channels[1].num); and continue until... alert(res.available_channels[***].num); http://js ...

The CSS transition will only activate when coupled with a `setTimeout` function

After using JavaScript to adjust the opacity of an element from 0 to 1, I expected it to instantly disappear and then slowly fade back in. However, nothing seems to happen as anticipated. Interestingly, if I insert a setTimeout function before applying th ...

Encountering repeated requests (duplicating calls) for each API request while using AngularJS with a JWT authentication token

I'm experiencing a problem with AngularJS(2/4) while attempting to make API calls. The issue arises when each API request contains a JWT Auth Token header, resulting in duplicate API calls. The first request returns no response (despite receiving a 20 ...

Display items in a not predetermined order

Despite its simplicity, I am struggling to get this working. My aim is to create a quiz program using JavaScript. Here is the basic structure: <ul> <li>option1</li> <li>option2</li> <li>option3</li> </ul> &l ...

Steps to create a thumbnail image following the insertion of an image into an input type="file" within a form, and subsequently submitting both elements on the form together

Currently, I am working on a form that enables users to upload images. Once the user submits the form, my goal is to create thumbnails for each image on the front-end and save them on the server afterwards. Due to security restrictions, changing the value ...

The Ajax request is failing to execute the callback function upon completion

While trying to upload an image using AJAX, I'm facing an issue where the success function is not being called upon completion. Within a form, there are two objects: <img class="b_logo" id="b_logo_img" src="images/no_image.gif"> <input cla ...

Utilizing Selenium Webdriver to efficiently scroll through a webpage with AJAX-loaded content

I am currently utilizing Selenium Webdriver to extract content from a webpage. The challenge I'm facing is that the page dynamically loads more content using AJAX as the user scrolls down. While I can programmatically scroll down using JavaScript, I a ...