The utilization of the $.ajax() function to retrieve data from a remote URL

My task involves reading this remote XML file: , in an HTML file using Ajax! This is the code I have written:

<script type="text/javascript">

getReadXmlFile();

function getReadXmlFile(){
    alert("Searching for file");
    $.ajax({
        type: "GET",
        url: "http://www.velib.paris/service/stationdetails/paris/901",
        dataType: "xml",
        success: parseXml
    });
    alert("Obtaining file");
}

function parseXml(xml){
    alert('Parsing started');
    var up = $(xml).find("updated").text();
    alert(up);
}        
</script>

Unfortunately, it's not working and I don't know why. Thank you for your help! I really need assistance!

Answer №1

I tested out your code on JSFiddle (with some unrelated modifications) and it seems to be functioning correctly.

getReadXmlFile();

function getReadXmlFile(){
  alert("searching for file");
  $.ajax({
    type: "POST", // The use of POST method is specific to JSFiddle, unrelated to the issue
    url: "/echo/xml/",
    dataType: "xml",
    data: {
      xml: `
        <?xml version="1.0" encoding="utf-8"?>
        <station>
          <available>1</available>
          <free>19</free>
          <total>20</total>
          <ticket>1</ticket>
          <open>1</open>
          <updated>1472183109</updated>
          <connected>1</connected>
         </station>
      `
    },
    success: parseXml
  });
  alert("file obtained");
}

function parseXml(xml){
  alert('starting to parse');
  var up=$(xml).find("updated").text();
  alert(up);
}    

View this JSFiddle

Since you're not receiving any error messages, make sure that jQuery is loaded correctly in your 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

JavaScript - AJAX Call Terminated after a Period on Secure Socket Layer (SSL)

Currently, my AJAX calls over an SSL connection using the Prototype JS framework run smoothly initially. However, after 10 seconds of being live on the page, they start failing with a status of 0 or 'canceled' in the Network Inspector... This is ...

What is the process of using JavaScript code to read a text file?

Trying to use Google Charts while reading data from a text file. The code in JS is written for this purpose: function readTextFile(file){ var rawFile = new XMLHttpRequest(); rawFile.open("GET", file, false); // using synchronous call var allTe ...

Is it possible for an AJAX request to return both HTML data and execute callback functions simultaneously?

Is it possible to update the content of an HTML div and call a JavaScript function with specific parameters obtained through AJAX after the completion of the AJAX request, all within a single AJAX call? ...

Leveraging the Content-Length Header in Scrapy Requests

This is the specific page I am attempting to crawl, and this is the corresponding AJAX request that fetches the necessary data. I have replicated the same AJAX request with identical headers and request payload. While the request does not error out, it re ...

Is there a specific asp.net ajax script reference that is compulsory to include?

In my asp.net web application, I utilize ModalPopupExtender and Accordion controls on various pages. After using firebug to profile the scripts, I have noticed a high number of ScriptRefrence.axd files being loaded. I am now wondering which of these scri ...

Display loading spinner and lock the page while a request is being processed via AJAX

Currently, I am working on a project using MVC in C#, along with Bootstrap and FontAwesome. The main objective of my project is to display a spinner and disable the page while waiting for an ajax request. Up until now, I have been able to achieve this go ...

Is there a way to customize the color of specific sections on a dygraph chart?

I am looking to incorporate dygraphs into my website, but I need help with displaying a specific background color in certain parts of the chart. For example, I want the chart to show green during daylight hours. Can you assist me in achieving this? ...

When using $.ajaxSetup, the content type is not configured for Get requests

Snippet 1 $.ajax({url:"1.aspx/HelloWorld",type:"GET",dataType:"json",contentType:"application/json"}); Snippet 2 $.ajaxSetup({ contentType: "application/json", dataType: "json" }); $.get( ...

When incorporating ajax in conjunction with a django form, an error arises indicating "Please choose a valid option. It should not be one of the choices provided."

I am a beginner in Django. Currently, I am using simple AJAX to dynamically update the choice field semester. It updates based on the selection of the course. However, I encounter an error when submitting the form which says Select a valid choice. The sele ...

Is it possible to only show the div element in my AJAX request without displaying the entire page

Is it possible to only show a specific div in my ajax request without displaying the entire page? The entire page is loaded, but I only want to display one div and hide the header and footer. However, I still need the header to be present on the page. jQ ...

Extracting data from XML using my custom script

I attempted to extract a specific value from an XML feed, but encountered some difficulties. In addition to the existing functionality that is working fine, I want to retrieve the value of "StartTime" as well. Here is the relevant section of the XML: < ...

The absence or inaccuracy of CSRF token in Django, Django REST Framework, and Internet Explorer

Our Django App uses REST Framework in a setup with nginx, redis, celery, gunicorn, and PostgreSQL. The system consists of only one App server. For ajax calls, we utilize the following function : $.ajaxSetup({ beforeSend: function (jqXHR, settings) { ...

Retrieving FormData() values in ASP.NET MVC controller

My code currently utilizes FormData() to transmit data from an Ajax request to an ASP.NET MVC controller. However, I am facing a challenge when attempting to retrieve this data within my controller. While I am able to successfully obtain file data using: ...

Using JSON data that has been returned to populate a table - Tablednd

I am enhancing a wishlist plugin to allow the user to rearrange the table by dragging and dropping items. Currently, I have implemented jQuery Tablednd with the return of JSON data after making an ajax call. The functionality is working fine. However, I a ...

Trouble with Nextjs link not functioning properly with a URL object when incorporating element id into the pathname

Recently I added translations to my website, which means I now need to use a URL object when creating links. Everything has been going smoothly with this change except for one issue: when I try to click a link that points to /#contact. When simply using h ...

Transferring live data between AJAX-triggered pop-up windows

Utilizing modals frequently in my application is a common practice. There are instances where I need to transfer data from one modal box to another. For instance: Suppose there is a table listing different car manufacturers (Audi, BMW, Honda, etc). Each r ...

Error: JQuery Ajax Success Handler cannot locate class method

There is a javascript Class in my code that successfully posts data, but encounters an issue when trying to access a specific function within a success handler. Although the function is found during the construction of the class and can be called from othe ...

Easy peasy add-to-cart functionality using AJAX

Hey everyone, I'm trying to figure out how to add items to a cart and display them on the page without having to reload the entire page. It's been challenging for me, so I decided to start with a simple example to understand the logic better. In ...

The table refuses to load

I've been troubleshooting this issue for the past two days. The array is visible in the console, but it refuses to show up on the table. I've tried multiple approaches, but none seem to work. I suspect that "tobodyHtml" is not defined properly, a ...

Picture disappearing following the refresh of an AJAX iframe

Currently, I am developing a profile system where the user's profile is displayed in an iframe that reloads when the form submit button is clicked. The content updates successfully upon reloading, but there is an issue with images not displaying after ...