Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

if ( document . readyState = = = 'loading' ) { document.addEventListener ( ' DOMContentLoaded ' , readJSONFile ) ; } else { readJSONFile (

if(document.readyState === 'loading'){
document.addEventListener('DOMContentLoaded', readJSONFile);
}else {
readJSONFile();
}
function ajaxLoadFile(filename, callback){
let xobj = new XMLHttpRequest();
let bustCache ='?datetime='+ new Date().getTime();
xobj.open('GET', filename + bustCache, true);
xobj.onreadystatechange = function(){
if(xobj.readyState ==4 && xobj.status =="200"){
callback(xobj.responseText);
}
};
xobj.send(null);
}
function readJSONFile(filename, callback){
fetch(filename)
.then(response => response.json())
.then(data => callback(data))
.catch(error => console.error('Error reading the JSON file', error));
}
function booksObject(data){
const tableBody = document.querySelector('tbody');
createTableRows(data, tableBody);
}
function createTableRows(books, tableBody){
const fragment = document.createDocumentFragment();
for (const isbn in books){
const book = books[isbn];
const row = document.createElement('tr');
const isbnCell = document.createElement('td');
const titleCell = document.createElement('td');
const priceCell = document.createElement('td');
const quantityCell = document.createElement('td');
const totalCell = document.createElement('td');
isbnCell.textContent = isbn;
titleCell.textContent = book.title;
priceCell.textContent = book.price;
quantityCell.textContent = book.quantity;
totalCell.textContent = book.price * book.quantity;
row.appendChild(isbnCell);
row.appendChild(titleCell);
row.appendChild(priceCell);
row.appendChild(quantityCell);
row.appendChild(totalCell);
fragment.appendChild(row);
}
tableBody.appendChild(fragment);
}
readJSONFile('data/books.json', booksObject);
function booksObject(){
let books ={
9781118876138 : {
title : "DATA SCIENCE & BIG DATA ANALYSIS",
price : 60.24,
quantity : 1},
9781107186125 : {
title : "PRINCIPLES OF DATABASE MANAGEMENT",
price : 77.25,
quantity : 1},
9781587205880 : {
title : "CCNA ROUTING & SWITCHING PORTABLE COMMAND GUIDE",
price : 24.26,
quantity : 2},
9781119288312 : {
title : "CCNA ROUTING AND SWITCHING : EXAM",
price : 73.50,
quantity : 2},
9781305078628 : {
title : "HANDS-ON MICROSOFT WINDOWS SERVER 2016",
price : 108.75,
quantity : 1},
9781541895386 : {
title : "INTRODUCTION TO WEB DEVE",
price : 65.25,
quantity : 1},
9781943872381 : {
title : "MURACH'S PHP AND MYSQL",
price : 43.25,
quantity : 1},
9780134167008 : {
title : "REVEL FOR LIANG JAVA ACCESS CARD",
price : 86.75,
quantity : 1}
}}Uncaught ReferenceError ReferenceError: data is not defined
at readJSONFile (/Users/joelandlopez/Desktop/public_html/csci21at
I got these errors, how do i fix them
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems A Practical Approach To Design Implementation And Management

Authors: THOMAS CONNOLLY

6th Edition

9353438918, 978-9353438913

More Books

Students also viewed these Databases questions

Question

Define ethics in finance in your own words plus provide example

Answered: 1 week ago

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago