In my django app I display the user facebook friends list. In order to refresh it every 10 minutes, I put this list in an other view and html, and I used a get request to get it and display it on the page I wan't.
Here is the get_fb_friends.html file where I have the friends list: (this the html file I associated to a view I created. This is where I get the list I wan't to display on the page I show to the user):
{% for friend in group %}
<li>{{ friend.name }} </li>
{% endfor %}
And how I import it in my template: (this is the page where I wan't to display the list for the user).
JS:
setInterval(function(){
$.get('/mysite/get_fb_friends/', function(data) {
$('.get_fb_friends').html(data);
});
}, 600000);
return jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase()) >= 0;
};
$(function() {
$('#searchbox').on('keyup', function() {
var w = $(this).val();
if (w) {
$('#friendlist li').hide();
$('#friendlist li:Contains('+w+')').show();
} else {
$('#friendlist li').show();
}
});
});
HTML:
<div class='get_fb_friends'> </div>
Then, I wan't to include a search bar on top of this list, in order the user to be able to search the friends he wants. So in my get_fb_friends.html, I added:
HTML:
<input id="searchbox" type="text" placeholder="Search" />
<ul id="friendlist">
{% for friend in group %}
<li>{{ friend.name }} </li>
{% endfor %}
This search bar works perfectly if I use it on the page www.mysite/get_fb_friends, but not anymore once it's get by the jquery get request (i.e on the page where I wan't to display it for the user); I type one letter and all the names disappear.
It looks like when I get the html file through the jquery get function, it does not keep the 'li' I need in my jquery function.
Any idea on what is happening?
I hope my question is clear, thank you for your help.
EDIT:
My main page:
HTML:
<div class="friendlist" id="friendlist">
JS:
$.get('/mysite/get_fb_friends/', function(data) {
$('.friendlist').html($(data).find($('#friendlist').html()));
});
return jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase()) >= 0;
};
$(function() {
$('#searchbox').on('keyup', function() {
var w = $(this).val();
if (w) {
$('#friendlist li').hide();
$('#friendlist li:Contains('+w+')').show();
} else {
$('#friendlist li').show();
}
});
});
My remote page:
HTML:
<input id="searchbox" type="text" placeholder="Search" />
<ul id="friendlist" class="friendlist">
{% for friend in group %}
<li>{{ friend.name }}</li>
{% endfor %}
$.geteven more to$('.get_fb_friends').load('/mysite/get_fb_friends/');but that won't resolve any other issues