DamSi

Untitled

Dec 17th, 2014
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <meta charset="UTF-8"  lang="mk" http-equiv="Content-Type"/>
  5.         <title>Лабораториска вежба 9, JQuery,AJAX,JSON</title>
  6.         <script type="text/javascript">
  7.         function getData(){
  8.             var xmlhttp=new XMLHttpRequest();
  9.             var url = "cd_catalog.xml";
  10.             var x,xx,i;
  11.            
  12.             xmlhttp.onreadystatechange = function(){
  13.                 if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
  14.                     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>";
  15.                     x = xmlhttp.responseXML.documentElement.getElementsByTagName("CD");
  16.                     for(i=0;i<x.length;i++){
  17.                         txt=txt+"<tr>";
  18.                         xx=x[i].getElementsByTagName("TITLE");{
  19.                             try{
  20.                                 txt = txt + "<td>" + xx[0].firstChild.nodeValue + "</td>";
  21.                             }catch(err){
  22.                                 txt = txt + "<td> </td>";
  23.                             }
  24.                         }
  25.                         xx=x[i].getElementsByTagName("ARTIST");{
  26.                             try{
  27.                                 txt = txt + "<td>" + xx[0].firstChild.nodeValue + "</td>";
  28.                             }catch(err){
  29.                                 txt = txt + "<td> </td>";
  30.                             }
  31.                         }
  32.                         xx=x[i].getElementsByTagName("COUNTRY");{
  33.                             try{
  34.                                 txt = txt + "<td>" + xx[0].firstChild.nodeValue + "</td>";
  35.                             }catch(err){
  36.                                 txt = txt + "<td> </td>";
  37.                             }
  38.                         }
  39.                         xx=x[i].getElementsByTagName("COMPANY");{
  40.                             try{
  41.                                 txt = txt + "<td>" + xx[0].firstChild.nodeValue + "</td>";
  42.                             }catch(err){
  43.                                 txt = txt + "<td> </td>";
  44.                             }
  45.                         }
  46.                         xx=x[i].getElementsByTagName("PRICE");{
  47.                             try{
  48.                                 txt = txt + "<td>" + xx[0].firstChild.nodeValue + "</td>";
  49.                             }catch(err){
  50.                                 txt = txt + "<td> </td>";
  51.                             }
  52.                         }
  53.                         xx=x[i].getElementsByTagName("YEAR");{
  54.                             try{
  55.                                 txt = txt + "<td>" + xx[0].firstChild.nodeValue + "</td>";
  56.                             }catch(err){
  57.                                 txt = txt + "<td> </td>";
  58.                             }
  59.                         }
  60.                     }
  61.                     txt=txt+"</table>";
  62.                     document.getElementById("load").innerHTML=txt;
  63.                    
  64.                 }else{
  65.                     alert("Document is not ready or not loaded yet!");
  66.                 }
  67.                 xmlhttp.open("GET",url,true);
  68.                 xmlhttp.send();
  69.             }
  70.         }
  71.         </script>
  72.     </head>
  73.     <body>
  74.         <div id="load">
  75.             <button id="data" name="button" type="button" onclick="getData()">Get data</button><br/>
  76.             <select id="selection">
  77.                 <option id="title">TITLE</option>
  78.                 <option id="artist">ARTIST</option>
  79.                 <option id="country">COUNTRY</option>
  80.                 <option id="company">COMPANY</option>
  81.                 <option id="price">PRICE</option>
  82.                 <option id ="year">YEAR</option>
  83.             </select>
  84.             <span><input type="checkbox" id="c" checked/></span>
  85.         </div>
  86.     </body>
  87. </html>
Advertisement
Add Comment
Please, Sign In to add comment