Reputation: 4086
I have a very simple test with jQuery and a django view:
HTML - Includes jQuery.js
JavaScript - $(document).ready( $.get("/index/" ); )
Django urls.py:
(r'^index/', index_view ),
Django views.py:
def index_view(request): if request.GET: return HttpResponse( "RECEIVED GET" )
Debugging in browser, the javascript gets called but the view never displays "RECEIVED GET".
Upvotes: 1
Views: 4086
Reputation: 630579
First, you want to anonymous function here, like this:
$(document).ready(function() {
$.get("/index/");
});
Then, this only gets the response, it doesn't do anything with it, if you want to do something with the content, do it in the callback, like this:
$(document).ready(function() {
$.get("/index/", function(response) {
alert(response);
});
});
Upvotes: 3