AJAX 与Django不重新加载页面,但循环将重新加载

jtw3ybtb  于 2022-12-20  发布在  Go
关注(0)|答案(1)|浏览(126)
<div class="container" id="cd">
    <div class="row">
        <div class="col-2">
            <label for="serialno" class="h4 text-center mx-4"> S.No </label>
        </div>
        <div class="col-3">
            <label for="billno" class="h4 text-center"> Bill No</label>
        </div>
        <div class="col-5">
            <label for="Items" class="h4 text-center"> Items</label>
        </div>
        <div class="col-2">
            <label for="total" class="h4 text-center"> Total</label>
        </div>
        <hr>
    </div>
    {% for b,d in history.items %}
    <div class="row" id="refresh">
        <div class="col-2 py-2">
            <label class="h6">{{forloop.counter}}. | {{b.created_at}}</label>
        </div>
        <div class="col-3 py-2">
            <label class="h5">{{b}}</label>
        </div>
        <div class="col-5 py-2">
            {% for i in d %}
            <label class="h6">{{i.itemname}} x {{i.qty}} {{i.subtotal}}</label><br>
            {% endfor %}
        </div>
        <div class="col-2 py-2">
            <span class="h6">&#8377;</span>
            <label class="h6">{{b.grandtotal}}</label>
        </div>
    </div>
    {% endfor %}
</div>
<script>
    $(document).on('change','#myform',function(e){
        e.preventDefault();
        $.ajax({
                type:'POST',
                url:"{% url 'history' %}",
                data:{
                    tb1:$('#cal').val(),
                    csrfmiddlewaretoken:$('input[name=csrfmiddlewaretoken]').val(),
                },
                success:function(response){
                    
                },
        });
    });
    </script>

我如何才能重新加载此{% for b,d in history. items()%}而不使用ajax刷新页面使用ajax更改历史记录值的任何方法重要提示onchange事件处理的值
我正在尝试重新加载循环而不重新加载页面
我想在ajax调用后更改history. items()django变量的值,并且可以迭代相应的值

xu3bshqb

xu3bshqb1#

{% for b,d in history.items %}
<div class="row" id="refresh-main">
    <div class="row" id="refresh-child">    

        <div class="col-2 py-2">
            <label class="h6">{{forloop.counter}}. | {{b.created_at}}</label>
        </div>
        <div class="col-3 py-2">
            <label class="h5">{{b}}</label>
        </div>
        <div class="col-5 py-2">
            {% for i in d %}
            <label class="h6">{{i.itemname}} x {{i.qty}} {{i.subtotal}}</label><br>
            {% endfor %}
        </div>
        <div class="col-2 py-2">
            <span class="h6">&#8377;</span>
            <label class="h6">{{b.grandtotal}}</label>
        </div>
    </div>
</div>
{% endfor %}
<script>
    $(document).on('change','#myform',function(e){
        e.preventDefault();
        $.ajax({
                type:'POST',
                url:"{% url 'history' %}",
                data:{
                    tb1:$('#cal').val(),
                    csrfmiddlewaretoken:$('input[name=csrfmiddlewaretoken]').val(),
                },
                success:function(response){
                    var pageURL = $(location).attr("href");
                    $('#refresh-main').load(pageURL + ' #refresh-child'); 
                },
        });
    });
    </script>

相关问题