我是 django 和 jquery 的新手,我searching for a 'hello world' sample for jquery
使用的是 django1.3,当用户按下按钮或加载页面时,hello world 作为字符串 /json 从服务器返回到客户端。
注意:我使用的是 django1.3 和 python 2.7。对不起,这是一个非常基本的问题。
我成功地显示了一个字符串“This is Hello World by JQuery”,没有任何视图函数(仅使用 jquery)。但我不知道如何使用 jquery 函数中的视图函数如果有人有想法请帮助我。谢谢Advance.om 模板我尝试使用以下代码片段。
网址.py
(r'^hellofromserver/$',views.test),
def test(request):
if request.method == 'GET':
json = simplejson.dumps('hello world!')
return HttpResponse(json, mimetype = 'application/json')
jqueyhelloserver.html:
<html>
<head>
<title>jQuery Hello World</title>
<script type="text/javascript" src="{{STATIC_URL}}js/jquery-1.2.6.min.js"></script>
</head>
<body>
.....
<script type="text/javascript">
# how can I get'hello world' from test function(What is the sytax )
</script>
<div id="msgid">
</div>
</body>
</html>
如何从 jquery 调用函数“test”和“hellofromserver”?(来自模板)。