thexpand
thexpand

Reputation: 641

Multiple PJAX Requests

I am trying to update 2 separate divs with PJAX. My PJAX fails and only the second one is loaded. Here's an example:

<div id="content-1"></div>
<div id="content-2"></div>

<button onclick="
$.pjax({
url: 'content-1.php',
container: '#content-1',
push: false
});

$.pjax({
url: 'content-2.php',
container: '#content-2',
push: false
});
"></button>

The problem is that the 2 pjax requests can't run simultaneously and the second one overlaps the first one, so only the second one (the one with id="content-2") is updated. Push is set to false for a reason, I don't need the url to be pushed in that particular case, but I need it for other parts of the site.

Upvotes: 4

Views: 1719

Answers (1)

thexpand
thexpand

Reputation: 641

If the URL address does not need to be changed, AJAX should be used instead of PJAX. PJAX and AJAX do the same thing - update only a certain part of the HTML content, without reloading the whole page. However, PJAX changes the URL address in the address bar, so it should only be used in that particular way.

A good example of the usage of PJAX and AJAX is a simple gallery. If the page has to be changed, it is better to use PJAX, so that it could change the URL in the address bar, adding a GET parameter for the page. But it is more appropriate to use AJAX for getting additional information for a clicked image in a pop-up.

Upvotes: 2

Related Questions