A
A
Alexander2015-10-11 23:30:42
PHP
Alexander, 2015-10-11 23:30:42

Getting a specific block via ajax?

Hello, I'm familiar with ajax not so long ago, please help)
I have the following code:

$('#filter_form').submit(function(e){
        var str = $(this).serialize();
        $.ajax({
            type: "POST",
            url: "./",
            data: str,
            success: function(result){
                $('#users_wrap').html(result);
            }
        });
        return false;
    });


In success, I get the whole page, but I need, for example, only the main block, and not the entire page, how can this be implemented? Thank you all very much!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Ivan Volkov, 2015-10-11
@alex_p95

$('#users_wrap').html(result); replace with - console.log($('main').html());
I will be a telepath.

D
dk-web, 2015-10-11
@dk-web

Through the grid, the block id must be specified. I could be wrong, but the load method is needed.
$( "#result" ).load( "ajax/test.html #container" );

I
Ivan Koryukov, 2015-10-11
@MadridianFox

We need a separate file that will give only main. You can make the page itself be empty at first, but at the end of the download, the ajax request for this separate file would automatically leave. to get unfiltered data. Further, when entering data into the filter form, you can make ajax requests to the same separate file and replace the page content.
However, a slightly better way would be to include unfiltered content in the page at the stage of its generation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question