Encountered a problem while parsing an XML file using JavaScript from an external server

Currently, I am developing an iPhone application in HTML that needs to pull content from an XML file stored on a remote server and display it in a list.

I have successfully accomplished this task when the XML file is hosted on the same server using the following code:

    <body>
        <div id="container"> 
            <div id="header">
                <h1><a href="./">BurgerFast</a></h1>
                <p>Menú</p>
                <div>
                    <div id="nav">
                        <ul>
                            <span id="lista"></span>
                        </ul>
                    </div>
                    <div id="footer">
                        <ul>
                            <li><a href="/assets/cl.png">Acerca de</a></li>
                            <li><a href="/assets/cl.png">Ayuda</a></li>
                        </ul>
                    </div>
                </div>
            </div>
        </div;

        <script type="text/javascript">
        if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
        else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
        xmlhttp.open("GET","assets/note.xml",false);
        xmlhttp.send();
        xmlDoc=xmlhttp.responseXML;

        var item = xmlDoc.getElementsByTagName("item")

        var myElems = "";
        for(i = 0 ; i < item.length ; i++){
            myElems = myElems + "<li><a>" + item[i].getElementsByTagName("name")[0].childNodes[0].nodeValue + "</li></a>";
        }

        document.getElementById("lista").innerHTML =  myElems;


        </script>

    </body>

All has been working well since the XML file is stored on the same server. However, I want to enhance the app's functionality by enabling it to retrieve XML data from external servers. When I modify the line:

xmlhttp.open("GET","assets/note.xml",false);

to:

xmlhttp.open("GET","http://173.236.56.146/~crayonli/xml/note.xml", true);

I encounter the issue where xmldoc is null every time. This confuses me as the XML file itself remains unchanged.

If anyone could point out where I might be going wrong, I would greatly appreciate it!

Answer №1

Using XmlHttp across different domains is not possible due to lack of support for cross domains. To work around this issue, you can utilize a proxy mechanism or search for solutions like xmlhttp cross domain...

For more information, check out this link XmlHttp Cross Domain Proxy

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

Verifying if a particular track is currently playing in the HowlerJS playlist

I am currently experimenting with a HowlerJS playlist code and would like to create a button that can detect if a specific song in the playlist is playing. When this button is clicked, I want it to hide a certain line of text. However, my knowledge on this ...

Tips for retrieving the content of an input field using Angular

function HomeController($scope, navbarService) { var vm = this; $scope.showHeader = true; $scope.userNameNav =''; $scope.$on('toggleHeader', function(event, data) { $scope.showHeader = data; }); $s ...

Convert a negative number to ASCII representation

Currently, I am attempting to extract the longitude and latitude of a user in order to utilize it in a Yahoo API query for obtaining the WOEID based on these coordinates. Subsequently, the WOEID will be passed through to a weather API call. My current pre ...

"Troubleshooting: Mongoose uniqueness feature not functioning

I am encountering an issue with mongoose where 'unique:true' is not functioning as expected. Take a look at the schema I have formulated: var mongoose = require('mongoose'); var userSchema = mongoose.Schema({ username:{ type:St ...

Utilize the scope for promise .then() functions when calling a service

I've just started using AngularJS and I have a question about handling promises in controllers. In my controller, I'm calling a service that communicates with a webservice and returns a promise. I want to apply the data from the promise's s ...

Issue with window resize directive not functioning as expected

I have recently crafted a personalized directive in AngularJS. Here's the code snippet: var esscom = angular.module('esscom',['ngMaterial' ,'ngMessages','ui.bootstrap','ui.router']); esscom.directiv ...

html - automatically populating input fields when the page loads

Currently, I have an HTML form embedded in the view and I am looking for a way to automatically populate specific input fields with json variables obtained from the server. Instead of manually writing JavaScript code for each field, my goal is to access th ...

Display alert only when focus is lost (on blur) and a dropdown selection was not made

Utilizing Google Maps Places for autocompletion of my input, I am aiming to nudge the user towards selecting an address from the provided dropdowns in order to work with the chosen place. A challenge arises when considering enabling users to input address ...

How can I eliminate the hover effect from a div element?

I am facing an issue with implementing a zoom effect on hover for my list of products. When I do a long press on a product, it works the first time but not the second time. I suspect this is because the div remains in a hover state. I want to ensure that ...

An easy way to create an input field after clicking a button

When I try to add a field on Button Click, the default field is not showing and does not get added upon button click I have put in my best effort but I cannot figure out what the problem is. I have added functions and used Math to generate a unique id. Th ...

Using values from a select menu in a math calculation without including a decimal point

I am working with a dropdown menu that contains various values... <select id="number1a" onChange="Addition()"> <option value="0" selected>-</option> <option value="10">10</option> <option value="7.5">7.5</optio ...

Responsive jQuery drop-down navigation menu for touchscreen devices struggles with hiding one menu item while clicking on another

I'm currently working on implementing a dropdown navigation menu for touch devices utilizing jQuery. I have managed to successfully hide dropdowns when tapping on the menu item title or outside the navigation area. However, I am facing an issue where ...

Getting row data from ag-grid using the angular material menu is a straightforward process

I have a specific requirement in ag-grid where I need to implement a menu to add/edit/delete row data. Currently, I am using the angular material menu component as the cell template URL. However, I am facing an issue where when I click on the menu item, it ...

The selected value is not displayed in the Material UI select component

My select component is showing the menu items and allowing me to select them, but it's not displaying the selected value. However, its handle function is functioning correctly because when I choose an item, the value in the database gets updated. Bel ...

Using the useState hook with an array of objects is not functioning as intended

I have initialized a useState object in my file like this: const [comments, setComments] = useState({ step_up: [], toe_walking: [], toe_touches: [], squat: [], side_to_side: [], rolling: [], leg_lifts: [], hand_to_knees: [], floo ...

Adaptable Semantic UI form design

Welcome, internet friends! If anyone out there has a moment to spare and is familiar with Semantic UI, I could really use some assistance... Currently, I am working on a form that looks great on larger screens like this: https://i.stack.imgur.com/cafc5.j ...

Rejuvenate your Bootstrap Accordion with these Settings

Using bootstrap documentation, I have implemented an accordion in my web application with the following code: <div class="accordion" id="accordion2"> <div class="accordion-group"> <div class="accordion-heading"> <a class=" ...

Creating a stunning art exhibition using React Native

Currently, I am in the process of creating a gallery component that utilizes both the scrollview and image APIs. I'm curious about how the scrollview manages its child components when it scrolls down. Does it unmount the parts that are not currently ...

How to show multiline error messages in Materials-UI TextField

Currently, I am attempting to insert an error message into a textfield (utilizing materials UI) and I would like the error text to appear on multiple lines. Within my render method, I have the following: <TextField floatingLabelText={'Input Fi ...

Could you lend a hand in figuring out the root cause of why this Express server is constantly serving up error

I am encountering a 404 error while running this test. I can't seem to identify the issue on my own and could really use another set of eyes to help me out. The test involves mocking a request to the Microsoft Graph API in order to remove a member fro ...