I am returning a set of links from the database via ajax, like so:
function search_friends() {
who = $('input.search_term').val();
$.ajax({
type: "POST",
url: 'lib/search.php',
data: {who:who},
success: function(data) {
$('.search_results').html(data);
}
// dataType: 'json'
});
return false;
}
That will return something like:
<div class="search_results">
<p><b>results:</b></p>
user1 <a href="add_friend.php?pid=3" class="3">add friend</a>
<br>
user2 <a href="add_friend.php?pid=4" class="4">add friend</a><br><hr>
</div>
But as soon as the page loads (before the search is done), I have something like:
$('.search_results a').click(function() {
alert('code');
});
But that doesn't work because .search_results
div is returned via ajax.
How to solve this problem?