Skip to main content Link Search Menu Expand Document (external link) Copy Copied

Table of contents

  1. ajax2

(XMLHttpRequest)[https://developer.mozilla.org/ko/docs/Web/API/XMLHttpRequest]

const url = "https://dummyjson.com/products";
const req = new XMLHttpRequest();
let div = document.querySelector("div");
req.onload = (e) => {
	const datas = req.response; // not responseText

	for (data of datas.products) {
		let { brand, parent } = data;
		div.innerHTML += `brand: ${brand}, <br> parent: ${parent}<br><hr>`;
		console.log(brand, parent);
	}
};
req.open("GET", url);
req.responseType = "json";
req.send();


ajax2