jquery - Xml file contents not showing up in list on Wamp -


i have started using ajax methods after going w3schools , tried implement teachings in video saw. video is: http://www.bing.com/videos/search?q=ajax+read+xml+file+example&view=detail&mid=815376b884b91d80047d815376b884b91d80047d&first=0&form=nvpfvr

i have done codings , put files in www page of wamp. open local host , try load data in xml file there no data loaded <ul> tag kept empty ajax load process.

here code website named website.html

    <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>untitled document</title> <link href="style.css" rel="stylesheet" type="text/css" /> </head>  <body> <div class="wrapper"> <div class="central_contents"> <div class="header"></div> <div class="main">  <ul> </ul>  </div> </div> </div> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"> </script> <script type="text/javascript" src="myjquery.js"></script> </body> </html> 

the jquery file named myjquery.js:

$(document).ready(function(){ corporatedata();                            //you must set time interval in ajax reloads page. fetch(); });   function fetch(){   //this function update data in site using ajax settimeout(function(){                     corporatedata();                     fetch();  /*this neat part. function used refresh data , calls after                     thousand milliseconds (after every second). page keep on refreshing after every                     1 second                     */                     },1000);     }   function corporatedata(){  $.ajax({                     url: "corporatedata.xml",                     datatype: "xml",                     success: function(data){                     $("ul").children.remove();                     $(data).find("employee").each(function(){                      /*.each here means must each employee in xml file*/                         var info='<li>name: '+$(this).find("name").text()+'</li><li>age: '+$(this).find("age").text()+'</li><li>company: '+$(this).find("company").text()+'</li>';                         $(ul).append(info);                                                                });      //.each() end             }  });   //$.ajax end  } //corporatedata() end 

here xml file

<?xml version="1.0" encoding="utf-8"?> <corporate> <employee>     <name>ahmed</name>     <age>20</age>     <company>yellowcorp</company> </employee> </corporate> 

what want achieve: want read data in xml file empty <ul> tags have put in html file. run them in local host of wamp , far have had no results

ok, if not working lets start removing of complexity. lets start removing settimeout complexity.

`by way if want more 1 visitor @ time doing once evry second seems way cripple server'

try see errors might getting. run browsers debugger. can set breakpoints , view variables see happening.

$(document).ready(function(){     getxmlfile();                            });   function getxmlfile(){      $.ajax({             type: "get",             url: "corporatedata.xml",             datatype: "xml",             error: function(jqxhr, textstatus, errorthrown) {                alert('getxmlfile failed ' + textstatus);             },             success: function(data, status){                 alert( 'getxmlfile status = ' + status );                 // did data returned                 alert( 'getxmlfile data = ' + data );                 $("ul").children.remove();                 $(data).find("employee").each(function() {                     var info = '<li>name: ' + $(this).find("name").text() +                                 '</li><li>age: ' + $(this).find("age").text() +                                  '</li><li>company: ' + $(this).find("company").text() + '</li>';                     $(ul).append(info);                                                            });        }      });   //$.ajax end  } //end getxmlfile 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -