N
N
nurzhannogerbek2018-02-03 11:28:07
Django
nurzhannogerbek, 2018-02-03 11:28:07

Infinite scaling not working after AJAX update?

Hello, please help me understand.

I'm using the django-el-pagination app for infinite scrolling (pagination on scroll). The user is shown a list of documents. Each such document has a button for editing, by pressing which the editing form opens. After successful editing, the list of documents is updated. The problem is that after the list has been updated via AJAX, infinite scrolling does not work. New documents are not loaded. How to solve this problem?

Usually, when scrolling, a request is sent to this url:

GET /documents/?page=2&querystring_key=page HTTP/1.1" 200 95118


But when I try to hack in the updated list in the terminal, I see the following url:
GET /documents/2225/edit/?page=2&querystring_key=page HTTP/1.1" 200 6230


I also see the following in the browser console:
TypeError: fragment.trim is not a function
el-pagination.js:72:50


main_template.html:
<div id="documents" class="dd">
        <ol class="dd-list">
            {% include page_template %}
        </ol>
    </div>

   {% block script %}
    {# START: AJAX request to endless pagination #}
    <script type="text/javascript">
        function activatePagination(){
            $.endlessPaginate({
                paginateOnScroll: true,
                onCompleted: function(context, fragment) {
                    activateTooltip();
                }
            });
        }
        activatePagination();
    </script>
    {# END: AJAX request to endless pagination #}

   <script src="{% static 'js/documents/crud.js'%}"></script> {# CRUD JS #}
   {% endblock %}


crud.js:
$(function () {
    $("#document-modal").on("submit", ".document-edit-form", function(e) {e.preventDefault(); saveForm.call(this, "Data successfully updated");});

    var saveForm = function(success_message) {
        var form = $(this);
        var formData = new FormData(form[0]);
        $.ajax({
            url: form.attr("action"),
            data: formData,
            type: form.attr("method"),
            dataType: 'json',
            success: function (data) {
                if (data.form_is_valid) {
                    // Update list of documents
                    $("#documents ol.dd-list").html(data.html_documents);

                    activatePagination();

                    // Hide modal
                    $("#document-modal").modal("hide");

                    // Show message to user
                    $("#user-action-message").fadeIn("slow");
                    setTimeout(function() {$("#user-action-message").fadeOut("slow");}, 2000);
                }
            },
            cache: false,
            contentType: false,
            processData: false,
        });
        return false;
    };
});

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question