Saving Pjax User Data

I use Pjax on the site that I create, and after searching around, I could not find a way to save user data for later search. This is my code:

var myData = {
        tst1: "some value",
        tst2: "some other value"
    };
$(document).pjax('a[pjax]', '#content', { //id to be loaded into
        fragment: '#content', //id to be loaded
        timeout: 3000,
        data: myData
    });

When I try to write event.state.data to the "pjax: popstate" event, I get undefined.

$(document).bind("pjax:popstate", function(event) {
        console.log(event.state.data);
});

Can someone tell me what I'm doing wrong?

+4
source share
1 answer

What are you really trying to achieve here? pjax:popstate- This is a browser event for the forward / back button according to: https://github.com/defunkt/jquery-pjax#events and does not accept any parameters.

The syntax for the parameters: $(document).pjax(delegation selector, container selector, options object).

PJAX : fire('pjax:end', [xhr, options]), options.option :

$(document).bind("pjax_event", function(xhr, options) {
    console.log(options.data);

});

. .

0

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


All Articles