vue 전단과django 백엔드 데이터 상호작용

4390 단어
//        /airCdt/ django          

onSubmit(){
const dict={
'floor': this.formLabelAlign.floor,
'room': this.formLabelAlign.room,
'status': this.formLabelAlign.status,
'mode': this.formLabelAlign.mode,
'temp': this.formLabelAlign.temp,
'level': this.formLabelAlign.level,
};
$.get("/airCdt/", dict, function (ret) {

// console.log(ret);
$("#respond").html(ret);
});


},

//
$.get("/api/floor2_ajax/", (ret) =>{
var data = JSON.parse(ret);
this.tableData[3]["data"] = Number(data[room-1]["fields"]["temp"]).toFixed(1);
localStorage.setItem("temp_8229",this.tableData[3]["data"]);
var status = data[room-1]["fields"]["status"];
if (status =='0'){
this.tableData[0]["data"] = ' ';
}
else if(status =='1'){
this.tableData[0]["data"] = ' ';
}
else{this.tableData[0]["data"]=' ';}
localStorage.setItem("status_8229",this.tableData[0]["data"]);
var mode = data[room-1]["fields"]["mode"];
if (mode =='1'){
this.tableData[1]["data"] = ' ';
}
else if(mode =='2'){
this.tableData[1]["data"] = ' ';
}
else if(mode=='3'){
this.tableData[1]["data"] = ' ';
}
else{this.tableData[1]["data"] = ' ';}
localStorage.setItem("mode_8229",this.tableData[1]["data"]);
var level = data[room-1]["fields"]["level"];
if (level =='1'){
this.tableData[2]["data"] = ' ';
}
else if(level =='2'){
this.tableData[2]["data"] = ' ';
}
else if(level=='3'){
this.tableData[2]["data"] = ' ';
}
else if(level=='4'){
this.tableData[2]["data"]= ' ';
}
else{this.tableData[2]["data"] = ' ';}
localStorage.setItem("level_8229",this.tableData[2]["data"]);
this.tableData[5]["data"] = data[room-1]["fields"]["co2"];
localStorage.setItem("co2_8229",this.tableData[5]["data"]);
this.tableData[7]["data"] = Number(data[room-1]["fields"]["tvoc"]).toFixed(3);
localStorage.setItem("tvoc_8229",this.tableData[7]["data"]);
this.tableData[4]["data"] = Number(data[room-1]["fields"]["hum"]).toFixed(1);
localStorage.setItem("hum_8229",this.tableData[4]["data"]);
this.tableData[6]["data"] = data[room-1]["fields"]["pm25"];
localStorage.setItem("pm25_8229",this.tableData[6]["data"]);
})

#           ajax    
path('api/floor2_ajax/', api.floor2_Data),
path('floor2/', views.floor2),
path('api/floor3_ajax/', api.floor3_Data),
path('floor3/', views.floor3),
path('api/floor4_ajax/', api.floor4_Data),
path('floor4/', views.floor4),
path('api/floor5_ajax/', api.floor5_Data),
path('floor5/', views.floor5),
path('api/floor6_ajax/', api.floor6_Data),
path('floor6/', views.floor6),
path('test/', views.TesT),
#
path('airCdt/', views.airCdt),
path('freshAir/', views.freshAir),

view
#       
def airCdt(request):

floor = request.GET['floor']
room = request.GET['room']
status = request.GET['status']
mode = request.GET['mode']
temp = request.GET['temp']
level = request.GET['level']
print(floor, room, status, mode, temp, level)
  #
return HttpResponse(" ok")

전재 대상:https://www.cnblogs.com/nuister/p/11564597.html

좋은 웹페이지 즐겨찾기