【发布时间】:2011-11-28 09:21:53
【问题描述】:
我是 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 函数中的视图函数 如果有人有想法请帮助我。在此先感谢.om 模板 我尝试使用以下代码 sn-ps。
urls.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'?(来自模板)。
【问题讨论】:
-
我只需要知道jquery如何与服务器通信?
标签: jquery python django django-templates django-1.3