<!DOCTYPE html>
<html>
<head>
<title>example</title>
</head>
<body>
<div>
<a href = "/post1">link 1</a><br>
<a href = "/post2">link 2</a><br>
<a href = "/post3">link 3</a><br>
<a href = "/post">link 4</a><br>
<a href = "/post5">link 5</a><br>
<a href = "/post6">link 6</a><br>
</div>
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script>
$('a').click(function()
{
var href = $(this).attr('href'),
id = parseInt(href.substr(5));
if (typeof id != 'number' || isNaN(id))
return false;
$.ajax(
{
url: "test.html",
data:
{
id: id
}
}).done(function()
{
console.log('done!');
});
return false;
});
</script>
</body>
</html>