ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

ajax传参

2022-09-08 23:31:50  阅读:195  来源: 互联网

标签:传参 obj author publish ajax book id delete


{% extends 'home.html' %}
{% block contect %}
    <div class="container">
        <div class="row">

            <div class="col-md-7 col-md-offset-2">
                <a href="{% url 'book_add.view' %}" class="btn btn-success btn-xs">添加书籍</a>
                <a href="{% url 'home.view' %}" class="btn-xs btn">首页</a>
                <h1 class="text-center">数据展示</h1>
                <table class="table table-hover table-striped">
                    <thead>
                    <tr>
                        <th class="text-center">id</th>
                        <th class="text-center">title</th>
                        <th class="text-center">price</th>
                        <th class="text-center">publish</th>
                        <th class="text-center">publish_time</th>
                        <th class="text-center">author</th>
                        <th class="text-center">operation</th>
                    </tr>
                    </thead>
                    <tbody>

                    {% for book_obj in book_queryset %}
                        <tr>
                            <td class="text-center">{{ forloop.counter }}</td>
                            <td class="text-center">{{ book_obj.title }}</td>
                            <td class="text-center"> {{ book_obj.price }}</td>
                            <td class="text-center">{{ book_obj.publish.name }}</td>
                            <td class="text-center">{{ book_obj.publish_time|date:'Y-m-d' }}</td>
                            <td class="text-center">
                                {% for author_obj in book_obj.aithors.all %}
                                    {% if forloop.last %}
                                        <span>{{ author_obj.name }}</span>
                                    {% else %}
                                        <span>{{ author_obj.name }},</span>
                                    {% endif %}
                                {% endfor %}
                            </td>
                            <td><a href="{% url 'book_edit.view' book_obj.id %}" class="btn btn-primary btn-xs">编辑</a>
                                <a href="#" class="btn btn-danger btn-xs delBtn">删除</a>
                                <input type="text" id='delete_id' value="{{ book_obj.pk }}">
                            </td>
                        </tr>

                    {% endfor %}


                    </tbody>

                </table>

            </div>
        </div>

    </div>
{% endblock %}

{% block js %}

    <style>
        #delete_id {
            display: none;
        }
    </style>

    <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>

    <script>

        $('.delBtn').click(function () {
            swal({
                title: "Are you sure?",
                text: "Once deleted, you will not be able to recover this imaginary file!",
                icon: "warning",
                buttons: ['False','True'],
                dangerMode: true,
            })
                .then((willDelete) => {
                    let id=$('#delete_id').val()
                    if (willDelete) {$.ajax({
                            url:{% url 'delete_view' %},
                            type:'post',
                            data:{'delete_id':id},
                            success:function (args){console.log(args)}
                        })

                        swal("Poof! Your imaginary file has been deleted!", {
                            icon: "success",
                        });
                        function f(){window.location.href={% url 'book.view' %}}
                     setTimeout(f,1000)}
                    else {
                        swal("Your imaginary file is safe!");
                        return false
                    }
                });


        })

    </script>

标签:传参,obj,author,publish,ajax,book,id,delete
来源: https://www.cnblogs.com/tzmy/p/16671197.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有