So this is possibly a stupid question but I've been working on it for about 4 hours now. I'm self-taught in Python (meaning I'm passable but not great) and I'm trying to extend my scripting to Django. However, I need some client-side scripting and so I'm trying to do some very, very basic Javascript stuff using jQuery because there are lots of demos of that.
However, nothing is working. I can find tutorials like this one: http://webcloud.se/log/AJAX-in-Django-with-jQuery/ which look very helpful but they are missing information (in this case all that is given on the Javascript side is the code for a function without triggers). When I try to imbed the jQuery code I am given into a Django template it doesn't work but I can't tell whether that's because the stuff I wrote around the code I was given is at fault or because the stuff I was given is giving me problems because some setting somewhere is wrong.
Basically, I'd like to see a really simple example of sending data from Javascript to Django (say, sending the current timestamp) on a click and Django then posting that from both sides, completely. (I've looked at a lot of other StackOverflow answers for this type of question and all of them seem to be larger examples and I fear that I'm getting confused by some tangent that's irrelevant to the basic data-transfer problem.) I want to see the whole Django template with all the tags and the stuff that everyone skips, the URL file, and the views file. Then maybe I could figure out what's going on enough to start doing something with it.
Thanks in advance.
Update Actually, the problem may be more general. When I take this code:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Test</title>
</head>
<body>
<a href="http://jquery.com/">jQuery</a>
<script type="text/javascript" src="/usr/lib/pymodules/python2.6/django/contrib/admin/media/js/jquery.js"></script>`
<script>
$(document).ready(function(){
$("a").click(function(event){
alert("As you can see, the link no longer took you to jquery.com");
event.preventDefault();
});
});
</script>
</body>
</html>
and save it as an html file it runs fine. When I take that same code and make it a Django template (no changes except dropping it into the correct directory and making sure the template loader is set to load it) it suddenly doesn't work. I've tested it both in Firefox and Chrome.
Any thoughts?