problem with jquery ajax while loading data in django page
why following jquery code doesn't work when used with django while it works if loaded like static page?
there's probably django's csrf protection involved somewhere, but i can't find how to make it work.
edited, stripped down code:
$(document).ready(function(){
$('.content').load('something.txt');
$.ajax({
method: "get",url: "http://something.com/pm/js/something.txt",
success: function(html)
{
$(".content").html(html);
}
});
});
the purpose of this should be: when this django page loads, the script should call another django view(s) and load data from them. (at this mom开发者_运维技巧ent to make it easier 'something.txt' is static file)
...firebug doesn't show anything abnormal
I'm going to take a wild guess: maybe when you load the page with Django you don't have static file serving setup properly, so jQuery never gets loaded, and as such none of your Javascript gets executed.
To check and see if jQuery is getting loaded open firebug on that page and see if the jQuery
variable is undefined
.
If that's the problem just load jQuery from a CDN for now.
<script src="http://code.jquery.com/jquery-1.5.1.js"></script>
精彩评论