前端代码:
<textarea rows="50" cols="150" id="textarea"></textarea>
<script>
myVar = setInterval(function(){ mitimeer() },3000);
function mitimeer(){
console.log("11112");
$.get("/testajax/",function(data,status){
var result_txt = data; //接受的data在js里面是一个对象,需要使用对象.key的方式进行取值.
console.log(result_txt); document.getElementById("textarea").innerHTML = result_txt.result1;
});}
</script>
</div>
后端部分:
class LandPageAjaxView(LoginRequiredMixin,View):
def get(self,request):
result = read_result()
return JsonResponse({"result1": result})