1,安装django-ajax
2,简单用法
-
INSTALLED_APPS = (
-
'django.contrib.admin',
-
'django.contrib.auth',
-
'django.contrib.contenttypes',
-
'django.contrib.sessions',
-
'django.contrib.messages',
-
'django.contrib.staticfiles',
-
'polls',
-
'django_ajax',
-
)
-
#views.py
-
from django_ajax.decorators import ajax
-
-
@ajax
-
def my_view(request):
-
c = 2 + 3
-
return {'result': c}
{"status": 200, "statusText": "OK", "content": {"result": 5}}
-
#html
-
-
<!DOCTYPE html>
-
<html>
-
<head lang="en">
-
<meta charset="UTF-8">
-
{% load staticfiles %}
-
<script type="text/javascript" src="{% static 'jquery-2.1.3.js' %}"></script>
-
<script type="text/javascript" src="{% static 'django_ajax/js/jquery.ajax.min.js' %}"></script>
-
<title>ajax</title>
-
</head>
-
<body>
-
<h1>hello world hello world</h1>
-
<script type="text/javascript">
-
ajaxPost('ajax/', function(content){
-
//ajaxGet(...)
-
//onSuccess
-
console.log(content);
-
})
-
</script>
-
</body>
-
</html>
阅读(1923) | 评论(0) | 转发(0) |