I currently have the following Javascript, and I am not sure what I should put in for the commented area to check if the get returned any HTML?
$('#load-more').click(function() {
$.get('/load/friend/2'/, function(data) {
// If there is HTML returned, then $('#load-friend').append(data)
// Else $('#load-global').append(data)
});
});
The get queries /load/friend/2, which returns an HttpResponse object in Django that was rendered with render_to_response(template, context, RequestContext(request)).
The Django template looks like the following:
{% for review in reviews %}
// Code
{% endfor %}
So when $.get retrieves /load/friend/2 and reviews = [], I believe it should return an empty HTML document?
In the Django controller, if
reviewsis empty, return a http status code instead of the view template:In the JavaScript, use jQuery’s general AJAX function to define the callbacks: