Querying xml
Querying xml
Hi,
I'm trying to load xml using ajax call and later query the xml using a input field, the results of which should populate into a div. I would be searching by site id or title in the xml.
Right now, after the ajax call nothing happens. Please help me.
Thanks in advance for any help~~
Harish
-
<!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" />
<link rel="stylesheet" type="text/css" media="all" href="style.css" />
<script type="text/javascript" src="jquery.js"></script>
<title>Reading XML with jQuery</title>
<script>
$(document).ready(function(){
$.ajax({
type: "GET",
url: "sites.xml",
dataType: "xml",
success: function(){
console.log("Success"); }
});
});
$('#submit').click(function() {
$(xml).find('site').each(function(){
var id = $(this).attr('id');
var title = $(this).find('title').text();
var url = $(this).find('url').text();
$('<div class="items" id="link_'+id+'"></div>').html('<a href="'+url+'">'+title+'</a>').appendTo('#page-wrap');
$(this).find('desc').each(function(){
var brief = $(this).find('brief').text();
var long = $(this).find('long').text();
$('<div class="brief"></div>').html(brief).appendTo('#link_'+id);
$('<div class="long"></div>').html(long).appendTo('#link_'+id);
});
});
});
</script>
</head>
<body>
<form action="">
<b>Search: </b><input id="searchme" type="text" size="20"> <input id="submit" value="Submit" type="submit">
</form>
<div id="page-wrap">
<h1>Reading XML with jQuery</h1>
</div>
</body>
</html>