Skip to content

Commit 1ec6aaf

Browse files
committed
Document how pjax handles responses and X-PJAX-URL
1 parent 3358d5b commit 1ec6aaf

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,33 @@ An `X-PJAX` request header is set to differentiate a pjax request from normal XH
374374

375375
[Check if there is a pjax plugin][plugins] for your favorite server framework.
376376

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
396+
`X-PJAX-URL` header:
397+
398+
``` ruby
399+
def index
400+
request.headers['X-PJAX-URL'] = "http://example.com/hello"
401+
end
402+
```
403+
377404
#### Layout Reloading
378405

379406
Layouts can be forced to do a hard reload when assets or html changes.

0 commit comments

Comments
 (0)