search2.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>车辆违章查询</title>
  6. <style>
  7. * {
  8. font: 18px/30px Arial;
  9. }
  10. #container {
  11. width: 960px;
  12. margin: 0 auto;
  13. }
  14. #search {
  15. width: 720px;
  16. margin: 10px auto;
  17. padding-top: 100px;
  18. }
  19. #search input[type=search] {
  20. display: inline-block;
  21. width: 480px;
  22. height: 30px;
  23. }
  24. #search input[type=submit] {
  25. display: inline-block;
  26. width: 80px;
  27. height: 40px;
  28. border: None;
  29. background-color: red;
  30. color: white;
  31. margin-left: 20px;
  32. }
  33. #result {
  34. width: 920px;
  35. margin: 20px auto;
  36. border-collapse: collapse;
  37. }
  38. #result th {
  39. font-weight: bolder;
  40. border-bottom: 1px solid darkgray;
  41. }
  42. #result td, #result th {
  43. text-align: center;
  44. height: 50px;
  45. width: 180px;
  46. }
  47. </style>
  48. </head>
  49. <body>
  50. <div id="container">
  51. <form id="search" action="/search" method="post">
  52. <!-- 跨站身份伪造: 利用浏览器存储的cookie中的用户身份标识冒充用户执行操作 -->
  53. <!-- 防范跨站身份伪造最佳的做法就是在表单中放置随机令牌 -->
  54. <!-- 除此之外通过设置令牌还可以防范表单重复提交以及重放攻击 -->
  55. <!-- 隐藏域 / 隐式表单域: 页面上是无法看到该内容-->
  56. {% csrf_token %}
  57. <input type="search" id="carno" name="carno" placeholder="请输入你的车牌号" required>
  58. <input type="submit" value="搜索">
  59. <a href="/add">添加新记录</a>
  60. </form>
  61. <hr>
  62. <table id="result">
  63. <thead>
  64. <tr>
  65. <th>车牌号</th>
  66. <th>违章原因</th>
  67. <th>违章时间</th>
  68. <th>处罚方式</th>
  69. <th>是否受理</th>
  70. </tr>
  71. </thead>
  72. <tbody>
  73. </tbody>
  74. </table>
  75. <p>{{ last }}</p>
  76. </div>
  77. <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
  78. <script>
  79. $(function() {
  80. $('#search').on('submit', function(evt) {
  81. evt.preventDefault();
  82. var carno = $('#carno').val();
  83. var token = $('#search input[type=hidden]').val()
  84. $.ajax({
  85. url: '/search2',
  86. type: 'post',
  87. data: {
  88. 'carno': carno,
  89. 'csrfmiddlewaretoken': token
  90. },
  91. dataType: 'json',
  92. success: function(json) {
  93. $('#result tbody').children().remove();
  94. for (var i = 0; i < json.length; i += 1) {
  95. var record = json[i];
  96. var tr = $('<tr>').append($('<td>').text(record.carno))
  97. .append($('<td>').text(record.reason))
  98. .append($('<td>').text(record.date))
  99. .append($('<td>').text(record.punish));
  100. var imgName = record.isdone ? 'icon-yes.svg' : 'icon-no.svg';
  101. tr.append($('<td>').append($('<img>').attr('src', '/static/images/' + imgName)));
  102. $('#result tbody').append(tr);
  103. }
  104. }
  105. });
  106. });
  107. });
  108. </script>
  109. </body>
  110. </html>