You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+50-62Lines changed: 50 additions & 62 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
# pjax
1
+
# pjax = pushState + ajax
2
2
3
3
4
4
.--.
@@ -21,11 +21,15 @@
21
21
jgs |___\_.\_
22
22
`-"--'---'
23
23
24
-
## pjax = pushState + ajax
24
+
## Introduction
25
25
26
26
pjax is a jQuery plugin that uses ajax and pushState to deliver a fast browsing experience with real permalinks, page titles, and a working back button.
27
27
28
-
pjax works by grabbing html from your server via ajax and replacing the content of a container on your page with the ajax'd html. It then updates the browser's current url using pushState without reloading your page's layout or any resources (js, css), giving the appearance of a fast, full page load. But really it's just ajax and pushState.
28
+
pjax works by grabbing html from your server via ajax and replacing the content
29
+
of a container on your page with the ajax'd html. It then updates the browser's
30
+
current URL using pushState without reloading your page's layout or any
31
+
resources (JS, CSS), giving the appearance of a fast, full page load. But really
32
+
it's just ajax and pushState.
29
33
30
34
For [browsers that don't support pushState][compat] pjax fully degrades.
31
35
@@ -50,7 +54,9 @@ Consider the following page.
50
54
</html>
51
55
```
52
56
53
-
We want pjax to grab the url `/page/2` then replace `#pjax-container` with whatever it gets back. No styles or scripts will be reloaded and even the h1 can stay the same - we just want to change the `#pjax-container` element.
57
+
We want pjax to grab the URL `/page/2` then replace `#pjax-container` with
58
+
whatever it gets back. No styles or scripts will be reloaded and even the `<h1>`
59
+
can stay the same - we just want to change the `#pjax-container` element.
54
60
55
61
We do this by telling pjax to listen on `a` tags and use `#pjax-container` as the target container:
56
62
@@ -74,21 +80,21 @@ def index
74
80
end
75
81
```
76
82
77
-
If you'd like a more automatic solution than pjax for Rails check out [Turbolinks](https://github.com/rails/turbolinks).
83
+
If you'd like a more automatic solution than pjax for Rails check out [Turbolinks][].
78
84
79
-
Also check out [RailsCasts #294: Playing with PJAX](http://railscasts.com/episodes/294-playing-with-pjax)
85
+
Also check out [RailsCasts #294: Playing with PJAX][railscasts].
80
86
81
87
## Installation
82
88
83
89
### bower
84
90
85
-
Via [bower](https://github.com/twitter/bower).
91
+
Via [Bower][]:
86
92
87
93
```
88
94
$ bower install jquery-pjax
89
95
```
90
96
91
-
Or add `jquery-pjax` to your apps`bower.json`.
97
+
Or, add `jquery-pjax` to your app's`bower.json`.
92
98
93
99
```json
94
100
"dependencies": {
@@ -112,7 +118,9 @@ Requires jQuery 1.8.x or higher.
112
118
113
119
## Compatibility
114
120
115
-
pjax only works with [browsers that support the `history.pushState` API][compat]. When the API isn't supported pjax goes into fallback mode: `$.fn.pjax` calls will be a no-op and `$.pjax` will hard load the given url. This mode targets the browser requirements of the jQuery version being used.
121
+
pjax only works with [browsers that support the `history.pushState`
122
+
API][compat]. When the API isn't supported pjax goes into fallback mode:
123
+
`$.fn.pjax` calls will be a no-op and `$.pjax` will hard load the given URL.
116
124
117
125
For debugging purposes, you can intentionally disable pjax even if the browser supports `pushState`. Just call `$.pjax.disable()`. To see if pjax is actually supports `pushState`, check `$.support.pjax`.
118
126
@@ -190,7 +198,7 @@ if ($.support.pjax) {
190
198
191
199
### `$.pjax.submit`
192
200
193
-
Submits a form via pjax. This function is experimental but GitHub uses it on [Gist][gist] so give it a shot!
An `X-PJAX` request header is set to differentiate a pjax request from normal XHR requests. In this case, if the request is pjax, we skip the layout html and just render the inner contents of the container.
366
374
367
-
Check if your favorite server framework supports pjax here: https://gist.github.com/4283721
375
+
[Check if there is a pjax plugin][plugins] for your favorite server framework.
376
+
377
+
#### Response types that force a reload
378
+
379
+
By default, pjax will force a full reload of the page if it receives one of the
380
+
following responses from the server:
381
+
382
+
* Page content that includes `<html>` when `fragment` selector wasn't explicitly
383
+
configured. Pjax presumes that the server's response hasn't been properly
384
+
configured for pjax. If `fragment` pjax option is given, pjax will simply
385
+
extract the content to insert into the DOM based on that selector.
386
+
387
+
* Page content that is blank. Pjax assumes that the server is unable to deliver
388
+
proper pjax contents.
389
+
390
+
* HTTP response code that is 4xx or 5xx, indicating some server error.
391
+
392
+
#### Affecting the browser URL
393
+
394
+
If the server needs to affect the URL which will appear in the browser URL after
395
+
pjax navigation (like HTTP redirects work for normal requests), it can set the
**NOTE** The new api gives you control over the delegated element container. `$.fn.live` always bound to `document`. This is what you still want to do most of the time.
0 commit comments