S
S
Snewer2016-11-09 00:02:20
JavaScript
Snewer, 2016-11-09 00:02:20

Is it possible to update two blocks using Pjax?

Hello!
I am using Pjax widget in Yii2. On the product page there is a filter, as well as the results of applying the filter. Separately, the filter and separately the output of the results are wrapped in Pjax. Is it possible, when changing one block (filter), to update the data in both blocks with one request?
Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2016-11-09
@webinar

I'm not sure if it's possible with one request, but with one click it's possible for sure. Here are the docs on the script itself:
https://github.com/defunkt/jquery-pjax
Haven't tried it like this, but I think that there are 2 paths, or two containers that have the same linkSelector, or cling to the pjax:success event

S
sokollondon, 2019-08-05
@sokollondon

Option 1. Use normal ajax

$.ajax({
    'success': function(data){
        var targets = [
            '#container1',
            '#container2'
        ];
        $.each(targets, function (ind, t) {
            $(t).html($(data).find(t).html());
        });
    }
});

Option 2: Use pjax but there will be 2 requests
$.pjax.reload({container: "#container1", async:false});
$.pjax.reload({container: "#container2", async:false});

PS Pjax developers have been contacted since 2012 with a request to make 1 request, they do not plan to do so

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question