Reasons Behind the News Not Being Retrieved Using [XML JS Query]

Can you help me troubleshoot my code?

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>News Site</title>
<script>
window.document.onload = function () {
var xhttp = new XMLHttpRequest();
xhttp.open("GET", "cdcatalog.xml", true);
xhttp.send();
xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
        var xmlDoc = this.responseXML;
        console.log(xmlDoc);
        document.getElementById("demo").innerHTML = xmlDoc.getElementsByTagName("TITLE")[0].childNodes[0].nodeValue + "<br/>" + xmlDoc.getElementsByTagName("PRICE")[0].childNodes[0].nodeValue;
    } else {
    document.getElementById("demo").innerHTML = "Can't show it.";
        } 
    }
}
</script>
</head>
<body>
<div id="demo"></div>
</body>
</html>

I'm new to Ajax and despite checking and validating the code, nothing is being displayed on the page. It's just blank.

If anyone could point out where I'm going wrong, I would greatly appreciate it!

Answer №1

The document element does not contain an onload attribute. If you are trying to assign an event handler in that manner, you should use window.onload instead.

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

"The Ajax POST request to MyUrl returned a 404 error, indicating that the resource

While working on my Grails code, I encountered an error when the Ajax function received a response from the controller action. The parameters are being passed successfully by the Ajax function, and the controller function is executed. However, upon return ...

Generating RESTful URLs for an entity's attributes (Guide)

When designing restful URLs, I am faced with a dilemma regarding how to retrieve entities within my domain. The database at a lower level consists of many-to-many and one-to-many relationships involving Companies, Groups, and Users. The relationship betwee ...

What are the steps to resolve the issue of encountering the error message "Unrecognized custom element: <bot-ui>"?

I'm having some trouble setting up a chatbot screen with the "botui" and "vue-cli". Whenever I try to display the screen, I encounter an "Unknown custom element: " error. Below is the code snippet that I am using. Can you please help me figure out ...

Is there a way to restrict a user to selecting just one checkbox in a bootstrap checkbox group?

I am having trouble implementing bootstrap checkboxes in my code. I want the user to be able to select only one checkbox at a time, with the others becoming unchecked automatically. Can someone please advise me on what I need to add to my code? Here is a ...

ability to reach the sub-element dictionaries in typescript

class ProvinciaComponent extends CatalogoGenerico implements OnInit, AfterViewInit { page: Page = new Page({sort: {field: 'description', dir: 'asc'}}); dataSource: ProvinciaDataSource; columns = ['codprovi ...

Is there a way to modify the image source upon clicking a button?

I am currently working on implementing an image swap functionality on a webpage. I need the image to change when a user clicks a button, but for some reason, my logic isn't working. I am more interested in understanding why it's not working and w ...

Navigating through a sequence of URLs in Node.js, one by one

I am new to node js and experimenting with creating a web scraping script. I've received permission from the site admin to scrape their products as long as I make less than 15 requests per minute. Initially, my script was requesting all URLs at once, ...

"Utilizing Bootstrap's dropdown.js script independently: A Step-by-Step Guide

Has anyone been able to successfully use the Bootstrap dropdown.js component without integrating the entire Bootstrap library? I've attempted it, but haven't had any luck so far. Upon reading the documentation, it appears that the dropdown.js co ...

Update the page by selecting the refresh option from the drop-down menu

In my script, I have different views showing information retrieved from a database. One view displays the quantity of a product sold each month, another shows sales, the third presents profits, and the last exhibits calculated percentages using sales and p ...

What is the best way to retrieve the value from a textbox on the client side and then utilize it to generate

I am currently utilizing jQuery for my modal dialogs. My goal is to open a model dialog from one page and send some additional query strings to the modal dialog page. Is there a way to achieve something like this? <asp:HyperLink ID="hypClientSearch" ru ...

Leave a message | Google Sheets | JavaScript using nodeJS

I am having trouble adding comments to cells using the "Google Spread-Sheet" module in NODEJS. I have successfully written to cells, read from them, and deleted them, but I can't figure out how to add a comment to a cell. The tutorials I have found on ...

Revising the input value by updating the properties

After clicking on the Reset link, I encounter an issue where the input value fails to update properly. class DiscountEditor extends Component { render() { <div className="inline field"> <a className="ui reset" onClick={thi ...

Can you explain the relationship between HTML 5 Canvas coordinates and browser pixels?

When trying to use HTML 5 canvas as a drawing board in my application, I encountered an issue. The drawings appear at an offset from the mouse pointer. My method involves using the Jquery .offset function to determine the event's position on the canv ...

In TypeScript version 2.4.1, the fontWeight property encounters an error where a value of type 'number' cannot be assigned to the types of '"inherit", 400'

When attempting to set the fontWeight property in TypeScript, I encounter the following error: Types of property 'test' are incompatible. Type '{ fontWeight: number; }' is not assignable to type 'Partial<CSSProperties>&a ...

Trouble encountered while retrieving the data structure in order to obtain the outcome [VueJs]

I am facing an issue while trying to save information from an HTTP request into a structure and then store it in local storage. When I attempt to retrieve the stored item and print a specific value from the structure, it does not work! Here is my code: / ...

Is there a way to retrieve content in tinymce from a JSP file and send it to a servlet that then redirects to a different page

I need guidance on how to store the content from the tinymce editor and post it with a new page creation. What steps should I take? ...

Troubleshooting jQuery compatibility issues with Wordpress

Having some trouble implementing zclip on my Wordpress site to copy dynamically generated text. The code works fine as a standalone html page with embedded jquery, but it's not translating well to my Wordpress site. Even though I've placed the co ...

What is the best way to transfer a PHP string to JavaScript/JQuery for use in a function?

Within my PHP code, I have the following: $welcome = "Welcome!"; echo '<script type="text/javascript">addName();</script>'; Additionally, in my HTML/script portion: <a id="franBTN"></a> <script type="text/javascript ...

Switch out multiline text with javascript

Could someone assist me with this question? I am attempting to locate and replace specific code within a JavaScript file. The code is included in an AJAX response that contains a significant amount of HTML code. After retrieving the AJAX response, I stor ...

Considerations for Developing an AJAX-Powered Web Application

We are currently embarking on developing an AJAX-based web application that will involve exchanging information and generated HTML using JSON/POST techniques. Thanks to a cache layer incorporating memcached and disk-based caching, we can efficiently retrie ...