一、AJAX的异步示例
1. urls.py
AJAX异步、sweetalert、Cookie和Session初识
from django.conf.urls import url
from apptest import views


urlpatterns = [
    url(r'^atest/', views.atest),
    url(r'^ajax1/', views.ajax1),
    url(r'^ajax2/', views.ajax2),
]
View Code


2. atext.HTML
AJAX异步、sweetalert、Cookie和Session初识
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="content-type" charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Title</title>
</head>

<body>
<div>
    <input type="text" id="i1">
    <button id="b1">按钮1</button>
</div>

<div>
    <input type="text" id="i2">
    <button id="b2">按钮2</button>
</div>


<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
    // 点击按钮1给ajax1发送get请求
    $("#b1").click(function () {
        $.ajax({
            url: '/ajax1/',
            type: 'get',
            success: function (res) {
                $("#i1").val(res)
            }
        })
    });

    // 点击按钮2给ajax2发送get请求
        $("#b2").click(function () {
        $.ajax({
            url: '/ajax2/',
            type: 'get',
            success: function (res) {
                $("#i2").val(res)
            }
        })
    });


</script>

</body>
</html>
View Code

相关文章:

  • 2021-08-29
  • 2022-12-23
  • 2021-12-20
  • 2021-12-20
  • 2021-12-20
猜你喜欢
  • 2021-04-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-27
  • 2022-12-23
相关资源
相似解决方案