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))
相关阅读:
*** walker ***
转载于:https://blog.51cto.com/walkerqt/1231685