DjangoのシンプルなAJAXアプリケーション

htmlページ

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <h1>index首页</h1>

    <input type="text" id="i1">+
    <input type="text" id="i2">=
    <input type="text" id="i3">
    <input type="button" value="ajax提交" id="b1"><br>

<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script>
    $("#b1").on("click",function () {
        $.ajax({
            url:"/ajax_add/",
            type:"GET",
            data:{"i1":$("#i1").val(),"i2":$("#i2").val()},
            success:function (data) {
                $("#i3").val(data);
            }
        })
    })
</script>
</body>
</html>

デーモンコード

from ldap3 import Server, Connection, ALL, SUBTREE, ServerPool
from django.shortcuts import HttpResponse,render,redirect

def index(request):
    return render(request,"index.html")

def ajax_add(request):
    i1 = int(request.GET.get("i1"))
    i2 = int(request.GET.get("i2"))

    ret = i1+i2
    return  HttpResponse(ret)

業績

テキストボックスに2時01分を入力すると、背景を提出し、その結果3を返すために、AJAXをクリックすると、ラベルがI3に割り当てられました
DjangoのシンプルなAJAXアプリケーション

ます。https://blog.51cto.com/12965094/2411159で再現

おすすめ

転載: blog.csdn.net/weixin_33700350/article/details/93017588