简体   繁体   中英

Django - ajax call for loading page not working

I need really help..

I'm not good at front-end and I'm very confused with Ajax.

I'm trying to do an Ajax call for when I click on a button of my table so when I hit that button my ajax should show my animation .gif so the user should know that the page is loading.

my template:

<style>
    .ajaxProgress{
        display:none;
        text-align: center;

    }
</style>
<div id="output">
    <div class="ajaxProgress">
    <h3>Please wait..</h3>
    <img src="{% static 'img/ajax.gif' %}" alt="loading"/>
    </div>
</div>
            {% for item in qs  %}
            <tr> 
            <tbody>
                <td 
                a id="mqtt" class="btn btn-xs btn-info"   title="mqtt" href="javascript: startAjax(){% url 'start_mqtt' item.id %}"><span class="fa fa-signal"></span> </a> </td>
                </tbody>
            </tr>
            {% endfor %}
        </table>


        <script>

function startAjax() {
    $('.ajaxProgress').show();
    $.ajax({
        type: "GET",
        dataType:"json",
        async: true,
        data: { csrfmiddlewaretoken: '{{ csrf_token }}' },
        success: function(json){
            $('#output').html(json.message);
            $('.ajaxProgress').hide();
            GetRating(json.message);
        }
    })

}
</script>

Basically what I need is when I hit on the button should start my .gif but nothing happens....

var $loading = $('.ajaxProgress').hide();
$(document)
.ajaxStart(function () {
    $loading.show();
 })
.ajaxStop(function () {
     $loading.hide();
});

I like to use this way

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM