From b2731970be0e7d02809f5c39a786eab5b0f3d181 Mon Sep 17 00:00:00 2001 From: Jordan Date: Sat, 7 Jan 2017 14:08:31 -0700 Subject: [PATCH] Only update browser state on pjax success --- jquery.pjax.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/jquery.pjax.js b/jquery.pjax.js index bfcccce4..fbaebcab 100644 --- a/jquery.pjax.js +++ b/jquery.pjax.js @@ -288,8 +288,15 @@ function pjax(options) { fragment: options.fragment, timeout: options.timeout } + + if (options.push && !options.replace) { + // Cache current container element before replacing it + cachePush(previousState.id, cloneContents(context)) - if (options.push || options.replace) { + window.history.pushState(pjax.state, container.title, container.url) + } + + if (options.replace) { window.history.replaceState(pjax.state, container.title, container.url) } @@ -361,13 +368,6 @@ function pjax(options) { var xhr = pjax.xhr = $.ajax(options) if (xhr.readyState > 0) { - if (options.push && !options.replace) { - // Cache current container element before replacing it - cachePush(pjax.state.id, cloneContents(context)) - - window.history.pushState(null, "", options.requestUrl) - } - fire('pjax:start', [xhr, options]) fire('pjax:send', [xhr, options]) }