From b0748a2aa511a2b406780b69684922fab49e7ea7 Mon Sep 17 00:00:00 2001 From: Behind The Math Date: Tue, 27 Feb 2018 13:29:33 -0500 Subject: [PATCH] Trigger an error event if the response cannot be parsed. --- README.md | 2 +- lib/proto/handle-response.js | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 38efdb5..9c4bd5a 100644 --- a/README.md +++ b/README.md @@ -453,7 +453,7 @@ All events are fired from the _document_, not the link that was clicked. * `pjax:send` - Fired after the Pjax request begins. * `pjax:complete` - Fired after the Pjax request finishes. * `pjax:success` - Fired after the Pjax request succeeds. -* `pjax:error` - Fired after the Pjax request fails. +* `pjax:error` - Fired after the Pjax request fails. The request object will be passed along as `event.options.request`. `send` and `complete` are a good pair of events to use if you are implementing a loading indicator (eg: [topbar](http://buunguyen.github.io/topbar/)) diff --git a/lib/proto/handle-response.js b/lib/proto/handle-response.js index a4faa80..9b0410c 100644 --- a/lib/proto/handle-response.js +++ b/lib/proto/handle-response.js @@ -5,7 +5,10 @@ var trigger = require("./lib/events/trigger.js") module.export = function(responseText, request, href) { // Fail if unable to load HTML via AJAX if (responseText === false) { - trigger(document, "pjax:complete pjax:error", this.options) + var tempOptions = this.options + tempOptions.request = request + + trigger(document, "pjax:complete pjax:error", tempOptions) return } @@ -52,6 +55,10 @@ module.export = function(responseText, request, href) { this.loadContent(responseText, this.options) } catch (e) { + var tempOptions2 = this.options + tempOptions2.request = request + trigger(document, "pjax:error", tempOptions2) + if (!this.options.debug) { if (console && console.error) { console.error("Pjax switch fail: ", e)