A
A
Alexander Medvedev2017-05-28 03:10:02
MODX
Alexander Medvedev, 2017-05-28 03:10:02

How to make ajax loading from a block in the same document?

The task is to make an Ajax menu on one of the sections of the site under the control of MODX Revo. Unfortunately, I'm not very familiar with ajax. At the moment everything works like this

$(".menu-item").click(function(){
        var id = $(this).attr('id');
            $.ajax({
                type: "POST",
                url: "ajaxitems.html",
                data: ({findres:id}),
                success: function(content){
                $(".ordersItems").html(content);
                }
            });
    });

I would like the resources to be loaded not from a separate ajaxitems.html page (in this case), but from a specific block on the same page.

ps I display resources using this snippet


the snippet itself
<?php
if ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
   $data = $_POST;

   $params = array(
        'parents' => $data['findres'],
        'limit' => $limit,
        'tpl' => $tpl,
        'includeTVs' => $includeTVs,
        'hideContainers' => $hideContainers,
        'sortby' => $sortby
    );
    
    $output = $modx->runSnippet('pdoResources', $params);
    return  $output;
    
}


I would be very grateful if you point out flaws in the code, since I am also badly familiar with php (

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oleg Spiridonov, 2017-06-01
@hoqpe

Send a request to the same page, and instead of $(".ordersItems").html(content); output $(".ordersItems").html($(content).filter("#result_block")); where result_block is the id of the element containing the information you are interested in.

D
DarWiM, 2017-06-01
@DarWiM

Perhaps AjaxSnippet will help you

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question