1、前端。jquery发送get请求,并解析json数据。getjson方法可参考这里。
url = "http://example/?question=" + question + "&rand=" + math.random(); $.getjson(url, function(json){ answer = json.answer; alert(answer); });
2、后端。django接收get请求并返回json数据。
from django.http import httpresponse from django.utils import simplejson if request.method == 'get' and 'question' in request.get: question = request.get['question'] print(question) data = {"answer": "answer"} #ensure_ascii=false用于处理中文 return httpresponse(simplejson.dumps(data, ensure_ascii=false))
更多django返回json数据用法示例。
