Add checks for XHR redirects #101

Merged
BehindTheMath merged 2 commits from feature/detect-redirects into master 2018-01-10 15:45:56 -05:00
2 changed files with 18 additions and 1 deletions
Showing only changes of commit d1184aead6 - Show all commits

View File

@@ -159,7 +159,7 @@ Pjax.prototype = {
// Do the request
options.requestOptions.timeout = this.options.timeout
this.doRequest(href, options.requestOptions, function(html) {
this.doRequest(href, options.requestOptions, function(html, request) {
// Fail if unable to load HTML via AJAX
if (html === false) {
trigger(document,"pjax:complete pjax:error", options)
@@ -170,6 +170,18 @@ Pjax.prototype = {
// Clear out any focused controls before inserting new page contents.
document.activeElement.blur()
if (request.responseURL) {
if (href !== request.responseURL) {
href = request.responseURL
}
}
else if (request.getResponseHeader("X-PJAX-URL")) {
href = request.getResponseHeader("X-PJAX-URL")
}
else if (request.getResponseHeader("X-XHR-Redirected-To")) {
href = request.getResponseHeader("X-XHR-Redirected-To")
}
try {
this.loadContent(html, options)
}

View File

@@ -15,6 +15,11 @@ module.exports = function(location, options, callback) {
}
}
request.onerror = function (e) {
console.log(e)
callback(null, request)
}
request.ontimeout = function() {
callback(null, request)
}