Fix README. Also pass the current options object to loadContent()
Fixes #167
This commit is contained in:
@@ -172,7 +172,7 @@ pjax.loadUrl("/your-url")
|
|||||||
pjax.loadUrl("/your-other-url", {timeout: 10})
|
pjax.loadUrl("/your-other-url", {timeout: 10})
|
||||||
```
|
```
|
||||||
|
|
||||||
#### `handleResponse(responseText, request, href)`
|
#### `handleResponse(responseText, request, href, options)`
|
||||||
|
|
||||||
This method takes the raw response, processes the URL, then calls `pjax.loadContent()` to actually load it into the DOM.
|
This method takes the raw response, processes the URL, then calls `pjax.loadContent()` to actually load it into the DOM.
|
||||||
|
|
||||||
@@ -181,6 +181,7 @@ It is passed the following arguments:
|
|||||||
* **responseText** (string): This is the raw response text. This is equivalent to `request.responseText`.
|
* **responseText** (string): This is the raw response text. This is equivalent to `request.responseText`.
|
||||||
* **request** (XMLHttpRequest): This is the XHR object.
|
* **request** (XMLHttpRequest): This is the XHR object.
|
||||||
* **href** (string): This is the URL that was passed to `loadUrl()`.
|
* **href** (string): This is the URL that was passed to `loadUrl()`.
|
||||||
|
* **options** (object): This is an object with the options for this request. The structure basically matches the regular options object, with a few extra internal properties.
|
||||||
|
|
||||||
You can override this if you want to process the data before, or instead of, it being loaded into the DOM.
|
You can override this if you want to process the data before, or instead of, it being loaded into the DOM.
|
||||||
|
|
||||||
@@ -191,9 +192,9 @@ var pjax = new Pjax();
|
|||||||
|
|
||||||
pjax._handleResponse = pjax.handleResponse;
|
pjax._handleResponse = pjax.handleResponse;
|
||||||
|
|
||||||
pjax.handleResponse = function(responseText, request, href) {
|
pjax.handleResponse = function(responseText, request, href, options) {
|
||||||
if (request.responseText.match("<html")) {
|
if (request.responseText.match("<html")) {
|
||||||
pjax._handleResponse(responseText, request, href);
|
pjax._handleResponse(responseText, request, href, options);
|
||||||
} else {
|
} else {
|
||||||
// handle response here
|
// handle response here
|
||||||
}
|
}
|
||||||
|
|||||||
1
index.js
1
index.js
@@ -36,6 +36,7 @@ var Pjax = function(options) {
|
|||||||
var opt = clone(this.options)
|
var opt = clone(this.options)
|
||||||
opt.url = st.state.url
|
opt.url = st.state.url
|
||||||
opt.title = st.state.title
|
opt.title = st.state.title
|
||||||
|
// Since state already exists, prevent it from being pushed again
|
||||||
opt.history = false
|
opt.history = false
|
||||||
opt.scrollPos = st.state.scrollPos
|
opt.scrollPos = st.state.scrollPos
|
||||||
if (st.state.uid < this.lastUid) {
|
if (st.state.uid < this.lastUid) {
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ module.exports = function(responseText, request, href, options) {
|
|||||||
this.state.options = options
|
this.state.options = options
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.loadContent(responseText, this.options)
|
this.loadContent(responseText, options)
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
trigger(document, "pjax:error", options)
|
trigger(document, "pjax:error", options)
|
||||||
|
|||||||
Reference in New Issue
Block a user