• python学习-- django 2.1.7 ajax 请求


    #--------------views.py----------------------

    def add(request):
    a = request.GET['a']
    print(a)
    b = request.GET['b']
    a = int(a)
    b = int(b)
    return HttpResponse(str(a+b))

    #--------------templates/*.html----------------------
    {% extends 'base.html' %}
    {% load static %} #目的 <script src="{% static "js/jquery.min.js" %}"></script> 没有这个不现实 js引用
    {% block content %}
    <form action="/add/" method="get">
    a: <input type="text" id="a" name="a"> <br>
    b: <input type="text" id="b" name="b"> <br>
    <p>result: <span id='result'></span></p>
    <button type="button" id='sum'>提交</button>
    </form>

    <script src="{% static "js/jquery.min.js" %}"></script>
    <script type="application/javascript">
    $(document).ready(function(){
    $("#sum").click(function(){

    var a = $("#a").val();
    alert(a);
    var b = $("#b").val();
    alert(b);
    $.get("/add/",{'a':a,'b':b}, function(ret){
    $('#result').html(ret)
    })
    });
    });
    </script>
    {% endblock %}


    #-----------urls.py----------------------------------------------------------*

    urlpatterns = [
    path('add/',views.add,name='add'),
    path('admin/', admin.site.urls),
    ]

  • 相关阅读:
    bzoj2751
    bzoj1483
    bzoj1011
    bzoj1412
    bzoj1820
    bzoj1295
    bzoj3444
    Java--Exchanger用于进行线程间的数据交换
    Java--Semaphore控制并发线程数量
    Java--Spring AOP 源码散点记录(最后整理成一篇博客)
  • 原文地址:https://www.cnblogs.com/ln-qiqi/p/10528792.html
Copyright © 2020-2023  润新知