AJAX ﻞﯾﺎﻓ ﮏﯾ ﺎﺑ ﯽﻠﻣﺎﻌﺗ ﻁﺎﺒﺗﺭﺍ ﯼﺍﺮﺑ ﺪﻧﺍﻮﺗ ﯽﻣ XML ﺩﻮﺷ ﻩﺩﺎﻔﺘﺳﺍ.
ﺪﻨﮐ ﯽﺸﮐﺍﻭ ﺍﺭ ﺕﺎﻋﻼﻃﺍ ﺪﻧﺍﻮﺗ ﯽﻣ ﺏﻭ ﻪﺤﻔﺻ ﮏﯾ ﻪﻧﻮﮕﭼ ﻪﮐ ﺪﻫﺩ ﯽﻣ ﻥﺎﺸﻧ ﺮﯾﺯ ﻝﺎﺜﻣ
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<style>
table,th,td {
border : 1px solid black;
border-collapse: collapse;
}
th,td {
padding: 5px;
}
</style>
<body>
<h2>The XMLHttpRequest Object</h2>
<button type="button" onclick="loadDoc()">Get my CD collection</button>
<br><br>
<table id="demo"></table>
<script>
function loadDoc() {
const xhttp = new XMLHttpRequest();
xhttp.onload = function() {
myFunction(this);
}
xhttp.open("GET", "cd_catalog.xml");
xhttp.send();
}
function myFunction(xml) {
const xmlDoc = xml.responseXML;
const x = xmlDoc.getElementsByTagName("CD");
let table="<tr><th>Artist</th><th>Title</th></tr>";
for (let i = 0; i <x.length; i++) {
table += "<tr><td>" +
x[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue +
"</td><td>" +
x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue +
"</td></tr>";
}
document.getElementById("demo").innerHTML = table;
}
</script>
</body>
</html>
loadDoc()
،ﺪﻨﮐﯽﻣ ﮏﯿﻠﮐ ﻻﺎﺑ ﺭﺩ «CD ﺕﺎﻋﻼﻃﺍ ﺖﻓﺎﯾﺭﺩ»
.ﺪﻨﮐ ﯽﻣ ﻪﻓﺎﺿﺍ ﺍﺭ ﻊﺑﺎﺗ ،ﺪﻨﮐ ﯽﻣ ﺩﺎﺠﯾﺍ XMLHttpRequest
ﯽ
HTML ﮏﯾ ،ﺪﺷ ﻩﺩﺎﻣﺁ ﺭﻭﺮﺳ ﺦﺳﺎﭘ ﯽﺘﻗﻭ
function loadDoc() {
const xhttp = new XMLHttpRequest();
xhttp.onload = function() {myFunction(this);}
xhttp.open("GET", "cd_catalog.xml");
xhttp.send();
}
function myFunction(xml) {
const xmlDoc = xml.responseXML;
const x = xmlDoc.getElementsByTagName("CD");
let table="<tr><th>Artist</th><th>Title</th></tr>";
for (let i = 0; i <x.length;
i++) {
table += "<tr><td>" +
x[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue
+
"</td><td>" +
x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue
+
"</td></tr>";
}
document.getElementById("demo").innerHTML = table;
}
."https://basicit.org/js/cd_catalog.xml" :ﺖﺳﺍ ﺕﺭﻮﺻ ﻦﯾﺍ ﻪﺑ ﻻﺎﺑ ﻝﺎﺜﻣ ﺭﺩ ﻩﺪﺷ ﻩﺩﺎﻔﺘﺳﺍ XML