Dynamic content does not work when loading ajax

I am trying to load dynamic content after user login using $.ajax, for example:

$.ajax({
    url: "functions.php",
    type: "GET",
    data: login_info,
    datatype: 'html',
    async: false,
    success: function (response) {
        $('#main').html(response);
    }
});

The problem is that some events do not work when loading in this way. I set the buttons using the method .live(), but the sortable list, for example, does not work. How can I somehow update the DOM and tell jquery about these newly added elements?

Thank!

+3
source share
2 answers

You will need to reinitialize the user interface components in the callback $.ajax, for example:

$.ajax({
    url: "functions.php",
    type: "GET",
    data: login_info,
    datatype: 'html',
    async: false,
    success: function (response) {
        $('#main').html(response);
        $("#main .sortable").sortable();
    }
});
+1
source

. jQuery script .

this, ""

+2

Source: https://habr.com/ru/post/1742648/


All Articles