Can u help me, please! I need to render a new content, when i click on button without refresh page. Now I am using jQuery cookie plugin, save button id into cookie, then read in view that value and render page. But it does not look friendly :c
My JS:
function initBrandSelector() {
$('.tab button').click(function(){
var brand = $(this).val();
if (brand) {
$.cookie('current_brand', brand, {'path': '/', 'expires': 365});
} else {
$.removeCookie('current_brand', {'path': '/'});
}
location.reload(true);
return true;
});
}
$(document).ready(function(){
var brand = $.cookie('current_brand');
if (brand) {
$('.tab button[value=' + brand + ']').addClass("active");
}
initBrandSelector();
});
My view:
def smartphones_list(request):
current_brand = get_current_brand(request)
if current_brand:
smartphones = Smartphone.objects.filter(brand=current_brand)
else:
smartphones = Smartphone.objects.all()
context = paginate(smartphones, 6, request, {}, var_name='smartphones')
return render(request, 'main/smartphones_list.html', context)