DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Jquery Using Asp Server Page To Create Xml File

07.15.2008
| 7176 views |
  • submit to reddit
        // jquery using asp server page to create xml file 

labels.htm
<!DOCTYPE html PUBLIC "-//W3C//  DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">;
 <html>
   <head>
     <meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type">
     <title>Address book</title>
     <script src="jquery.js" type="text/javascript"></script>
     <script type="application/javascript">
     $(function() {
         $('#update-target a').click(function() {
             $.ajax({
                 type: "GET",
                 url: "labels.xml",
                 dataType: "xml",
                 success: function(xml) {
                     $(xml).find('label').each(function(){
                         var id_text = $(this).attr('id');
                         var name_text = $(this).find('name').text();
			 var address_text = $(this).find('address').text();
						 
                         $('<li></li>')
                             .html(name_text + ' (' + id_text + ')' + ' ' + address_text)
                             .appendTo('#update-target ol');
                     }); //close each(
                 }
             }); //close $.ajax(
         }); //close click(
     }); //close $(
     </script>
   </head>
   <body>
     <p>
       <div id='update-target'>
         <a href="#">Click here to load addresses</a>
         <ol></ol>
       </div>
     </p>
   </body>
 </html>

labels.asp
<%
Response.contenttype = "application/vnd.xml" 
Response.AddHeader "Content-Disposition", "filename=labels.xml" 
response.write("<?xml version='1.0' encoding='iso-8859-1'?>"&vbcrlf)
response.write("<labels>"&vbcrlf)
response.write("<label id='ep' added='2003-06-10'>"&vbcrlf)
response.write("<name>The name</name>"&vbcrlf)
response.write("<address>"&vbcrlf)
response.write("<street>45 Bryn Lane</street>"&vbcrlf)
response.write("<city>Hailey</city>"&vbcrlf)
response.write("<province>ID</province>"&vbcrlf)
response.write("</address>"&vbcrlf)
response.write("</label>"&vbcrlf)
response.write("<label id='tse' added='2003-06-20'>"&vbcrlf)
response.write("<name>Thomas Eliot</name>"&vbcrlf)
response.write("<address>"&vbcrlf)
response.write("<street>3 Prufrock Lane</street>"&vbcrlf)
response.write("<city>Stamford</city>"&vbcrlf)
response.write("<province>CT</province>"&vbcrlf)
response.write("</address>"&vbcrlf)
response.write("</label>"&vbcrlf)
response.write("<label id='lh' added='2004-11-01'>"&vbcrlf)
response.write("<name>Langston Hughes</name>"&vbcrlf)
response.write("<address>"&vbcrlf)
response.write("<street>10 Bridge Tunnel</street>"&vbcrlf)
response.write("<city>Harlem</city>"&vbcrlf)
response.write("<province>NY</province>"&vbcrlf)
response.write("</address>"&vbcrlf)
response.write("</label>"&vbcrlf)
response.write("<label id='co' added='2004-11-15'>"&vbcrlf)
response.write("<name>Christopher Okigbo</name>"&vbcrlf)
response.write("<address>"&vbcrlf)
response.write("<street>7 Heaven's Gate</street>"&vbcrlf)
response.write("<city>Idoto</city>"&vbcrlf)
response.write("<province>Anambra</province>"&vbcrlf)
response.write("</address>"&vbcrlf)
response.write("</label>"&vbcrlf)
response.write("</labels>"&vbcrlf)
%>