1、get请求,返回text
$.ajax({
contentType:"application/json",
type:"GET",
url:"http://127.0.0.1:8000/test/helloworld",
dataType:"text",
success:function (data){
console.log(data)
});
# 请求http://127.0.0.1:8000/test/helloworld
def hello(request):
return HttpResponse("Hello world ! ")
2、get 请求返回json
$.ajax({
contentType:"application/json",
type:"GET",
url:"http://127.0.0.1:8000/test/rtjson",
dataType:"json",
success:function (data){
console.log(data['age'])
});
#http://127.0.0.1:8000/test/rtjson
def rtjson(request):
data={
'patient_name': '张三',
'age': '25',
}
return HttpResponse(json.dumps(data),content_type='application/json')
3、get请求 带 param 返回json
$.ajax({
contentType:"application/json"