Code

Options

| Name | Type | Default | Description |
| locationAttribute | string | href | The attribute of the element that when clicked, pjax will look for to get the link to follow to get the page to load from. |
| pjaxLinkSelector | string |
a[data-pjax="true"]
| A selector for pjax to use to create links from. |
| analytics | Google Analytics | null | A Google Analytics object to track pageviews of pjax loaded pages. |
| preLoad | function(){} | null | A function that will be executed when a link is clicked, but before an ajax request is made to pull the page. |
| postLoad | function(){} | null | A function that will be executed after page content has been replaced. |
| onErrorLoading | function(){} | null | A function that will be executed if the page content could not be loaded. |

Usage

Pjax works by selecting a container and then giving it a function telling it what to do with the data retrieved from a followed link.

That is the minimum required client side to get a link like this \u0026lt;a href=”/home/other” data-pjax=”true”\u0026gt;Link\u0026lt;/a\u0026gt; to pull back the page at /home/other and insert that data into the #content container.

Server-side, a couple other things need to be done so that the outer content/layout of the page isn’t pulled back with the page content.

We need to check whether the request for the page required it’s layout or now. Pjax sends back a customer header X-PJAX so that the server can distinguish this.

In the _ViewStart.cshtml we check for it and return a different layout file.