Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8" lang="mk" http-equiv="Content-Type"/>
- <title>Лабораториска вежба 9, JQuery,AJAX,JSON</title>
- <script type="text/javascript">
- function getData(){
- var xmlhttp=new XMLHttpRequest();
- var url = "cd_catalog.xml";
- var x,xx,i;
- xmlhttp.onreadystatechange = function(){
- if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
- var txt = "<table border='1'><tr><th>TITLE</th><th>ARTIST</th><th>COUNTRY</th><th>COMPANY</th><th>PRICE</th><th>YEAR</th></tr>";
- x = xmlhttp.responseXML.documentElement.getElementsByTagName("CD");
- for(i=0;i<x.length;i++){
- txt=txt+"<tr>";
- xx=x[i].getElementsByTagName("TITLE");{
- try{
- txt = txt + "<td>" + xx[0].firstChild.nodeValue + "</td>";
- }catch(err){
- txt = txt + "<td> </td>";
- }
- }
- xx=x[i].getElementsByTagName("ARTIST");{
- try{
- txt = txt + "<td>" + xx[0].firstChild.nodeValue + "</td>";
- }catch(err){
- txt = txt + "<td> </td>";
- }
- }
- xx=x[i].getElementsByTagName("COUNTRY");{
- try{
- txt = txt + "<td>" + xx[0].firstChild.nodeValue + "</td>";
- }catch(err){
- txt = txt + "<td> </td>";
- }
- }
- xx=x[i].getElementsByTagName("COMPANY");{
- try{
- txt = txt + "<td>" + xx[0].firstChild.nodeValue + "</td>";
- }catch(err){
- txt = txt + "<td> </td>";
- }
- }
- xx=x[i].getElementsByTagName("PRICE");{
- try{
- txt = txt + "<td>" + xx[0].firstChild.nodeValue + "</td>";
- }catch(err){
- txt = txt + "<td> </td>";
- }
- }
- xx=x[i].getElementsByTagName("YEAR");{
- try{
- txt = txt + "<td>" + xx[0].firstChild.nodeValue + "</td>";
- }catch(err){
- txt = txt + "<td> </td>";
- }
- }
- }
- txt=txt+"</table>";
- document.getElementById("load").innerHTML=txt;
- }else{
- alert("Document is not ready or not loaded yet!");
- }
- xmlhttp.open("GET",url,true);
- xmlhttp.send();
- }
- }
- </script>
- </head>
- <body>
- <div id="load">
- <button id="data" name="button" type="button" onclick="getData()">Get data</button><br/>
- <select id="selection">
- <option id="title">TITLE</option>
- <option id="artist">ARTIST</option>
- <option id="country">COUNTRY</option>
- <option id="company">COMPANY</option>
- <option id="price">PRICE</option>
- <option id ="year">YEAR</option>
- </select>
- <span><input type="checkbox" id="c" checked/></span>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment