The website is up and running smoothly, except for encountering an XMLHttpRequest() error when trying to

I have developed a new website

My website functions smoothly on most browsers and iPhone simulators, but encounters issues when accessed from a real iPhone. I have traced the problem to XMLHttpRequest(). The XML data retrieval seems to be causing trouble, as it returns undefined when trying to read the children of [object Element]. This situation is quite perplexing and baffling for me.

Below is my code snippet for fetching the XML data:

function convertXml (path) {
    if (window.XMLHttpRequest){
        xmlhttp=new XMLHttpRequest(); 
    }else{
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.open("GET",path,false);
    xmlhttp.send();
    xml=xmlhttp.responseXML.getElementsByTagName("app");
    var foo = [];
    for (var i = 0; i <= xml.length-1; i++) {
        foo[i] = {};
        for (var j = 0; j <=xml[i].children.length-1; j++) { 
            foo[i][xml[i].children[j].tagName] = xml[i].children[j].innerHTML.trim();
        } 
     }
    return foo;
}

After extensive testing, I discovered that on an iPhone, the request returns an [object Document], while on a computer it returns an [object XMLDocument]. Although I am unsure of the significance of this difference, I believe it might be the root cause of my issue. Is there a way to convert between these types?

In an attempt to resolve the problem, I switched to using jQuery instead of plain JavaScript, but unfortunately, the issue still persists.

Here is the updated jQuery code:

function getXML (path) {

var response = $.ajax({ type: "GET",   
                    url: "testingXml.xml",   
                    async: false,
                  }).responseText;

parser=new DOMParser();
xmlDoc=parser.parseFromString(response,"text/xml");

return xmlDoc;
}

function xmlToObject (x) {
var xml = x.getElementsByTagName("app"); 
var foo = [];

for (var i = 0; i <= xml.length-1; i++) {
    foo[i] = {}; 
    for (var j = 0; j <=xml[i].children.length-1; j++) { 
        foo[i][xml[i].children[j].tagName] = xml[i].children[j].innerHTML.trim();  
    }
}
return foo;
}

To obtain the array, you can use this code

xmlToObject(getXML("testingXml.xml"))

The issue persists, functioning fine on a computer but not displaying properly on iPhone (Google, Safari, Firefox, Opera). It appears that the XML content is not being rendered appropriately on mobile devices.

Answer №1

Encountering

The use of Synchronous XMLHttpRequest on the main thread is now considered deprecated due to its negative impact on user experience. For further assistance, refer to

Upon accessing your webpage in Google Chrome, I am seeing this message in the console. This issue may be causing compatibility problems on iOS devices: Apple has chosen to block such requests on mobile devices to prevent browser freezing rather than just issuing a warning.

Consider using

xmlhttp.open("GET",path,true);

along with an xhr.onload handler as explained in MDN's "Synchronous and asynchronous requests".

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

I am currently working with CakePHP and am interested in learning how to expire the admin session

I'm having issues with the code in my UserController. When I open the admin panel in two tabs within the same browser and log out from one tab, I am unable to redirect to the login page from the other tab when clicking on any menu. function beforeFil ...

The v-for directive fails to display the contents of the array

I would like to display some data received from the server in a loop: The JSON data that I have received looks like this (seen in the browser console): fetched data is: {projs: Array(10), page_number: 1, total_pages: 1} page_number: 1 projs: Array(10) 0: ...

Enabling a checkbox grid for exclusive rectangular selections

Apologies for the confusing title, I struggled to come up with something more fitting. Let's say my client needs a square area on their homepage where they can upload images that will be placed within various boxes in a grid. The available box optio ...

Create interfaces for a TypeScript library that is available on npm for export

I have a project in TypeScript that I am packaging as a library to be used by both JavaScript and TypeScript projects. After compiling, I upload the .js and .d.ts files to npm. The main.ts file exports the following: interface MyInterface{ // ... } clas ...

Develop an archive for submission to the AppStore

I have recently started using a detach app in order to install firebase. This is my first time creating an application for iPhone, so I've been doing a lot of research. During my research, I came across the following resources: However, I encountere ...

Updating UITableView without reloading all cells using RxSwift

When it comes to achieving the desired result without using RxSwift, I can do so by following these steps. This method effectively plays the necessary animation on the row being removed without reloading the entire table: let item = self.dataSource[(indexP ...

Retrieve the hidden value buried within multiple layers of classes

I'm having trouble retrieving the value from the pickup-address class. Here is my current code. Can anyone help me identify where I might be going wrong? JS var pickupAddress = $('.timeline-item.active-item > .timeline-status > .pickup-add ...

Updating an item stored locally

I am currently working on a web application that utilizes local storage. I have successfully implemented functionality to add and delete items, but I am facing an issue with editing items. Although items can be edited as expected, upon refreshing the page, ...

Encountering 404 errors when reloading routes on an Angular Azure static web app

After deploying my Angular app on Azure static web app, I encountered an error. Whenever I try to redirect to certain routes, it returns a 404 error. However, if I navigate from one route to another within the app, everything works fine. I have attempted t ...

What is the best way to integrate Angular 5 with various sources of JavaScript code?

I am fairly new to angular. I am looking to merge an external angular script file and on-page javascript code with angular 5. I understand that angular does not typically allow for the inclusion of javascript code in html components, but I believe there m ...

Tips for enhancing the width of the extrude shape in the x and z axes using Three.js

After creating a shape using extrude geometry, I found that I needed to increase the thickness along the x and z axes. Although I used bevelThickness to increase the thickness along the y axis, I still need to adjust it further. For reference, please see ...

Tips for invoking a Server-Side Function from within a JavaScript Function

When my button is clicked, it triggers the following code: protected void Button6_Click(object sender, EventArgs e) { Page.ClientScript.RegisterStartupScript(this.GetType(), "myScript", "AnotherFunction();", true); } In addition, ...

Original: Custom/Modified 'Fibonacci' Number sequenceRevised: Personalized/Altered

I am looking to create a unique variation of the Fibonacci sequence. The implementation I have in mind is as follows: (FSM) - FSM(0) = 0, FSM(1) = 1, FSM(n) = FSM(n - 2) + FSM(n - 1) / n How can this be achieved using JavaScript? Specifically, I need to ...

Conceal the Navbar in React js when the user is in the dashboard

I am currently working on my collage project and I need to find a way to hide the navigation bar if the user is in either the admin, employee, or publisher dashboard. This means that the navbar should be hidden when the user is on the paths: /admin, /emplo ...

View content from a text file on a webpage

Hi everyone, I could really use some assistance with a project I'm currently working on. As someone who is new to programming, I am facing a challenge. My goal is to showcase the contents of a plain text file on a webpage. This text file, titled titl ...

attack using JavaScript, AJAX, and PHP from a remote location

One vulnerability of using Javascript is that it's a client-side language, making scripts accessible for reading and copying. Let's take a look at this code snippet as an example: <html> <head> <title>title</title> <s ...

What are the steps to organize an array of objects by a specific key?

Experimented with the following approach: if (field == 'age') { if (this.sortedAge) { this.fltUsers.sort(function (a, b) { if (b.totalHours > a.totalHours) { return 1; } }); this ...

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 ...

Surprising 'T_ENCAPSED_AND_WHITESPACE' error caught me off guard

Error: An error was encountered while parsing the code: syntax error, unexpected character (T_ENCAPSED_AND_WHITESPACE), expected identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\wamp\www\html\updatedtimel ...

Handling errors in image echo in PHP

My attempts to manage 404 images retrieved from omdbapi.com have failed due to issues in my code. I am currently looping through an array to create a movie list. echo '<a href="'.$oIMDB->getUrl().'" target="_new"><img class="i ...