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数据用法示例相关文章请关注PHP中文网!
查看更多关于Django返回json数据用法示例的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did86015