How turn off "replace url" in Pjax
Asked Answered
V

3

6

I use Pjax with tutorial from http://railscasts.com/episodes/294-playing-with-pjax?view=comments I don't need change url and this coffee script code doesn't work:

.....

$("a#flag-comments").click ->

....

$.pjax

container: '[data-pjax-container-flag]',

replace: false,

url: '/flag_comments'

....

Any idea?

Valenta answered 27/3, 2012 at 22:20 Comment(0)
L
-2

Edit: Please see clime's answer below - It appears my answer is no longer correct.


Since the point of PJAX (pushState AJAX) is updating the url, I don't think there is a way to disable it. If updating the url isn't what your after you may just want to be using standard AJAX? (essentially use JQuery to perform an ajax get of a given path, then shove the contents in to a container of your choice)

The "replace" option in the JQuery PJAX script simply toggles between using "replaceState" & "pushState" to update a pages url.

Sorry i couldn't be of more help.

Lingle answered 28/3, 2012 at 17:7 Comment(0)
R
13

Set push: false in options. In js, it would be:

$(document).pjax('a', '#pjax-container', {push: false})
Rhodes answered 19/7, 2013 at 15:46 Comment(0)
V
1

it's not very good but it's working....

> $(document)
>>      .on 'pjax:beforeSend', ->
>>          $.url_old = window.location.pathname
>>      .on 'pjax:success', ->
>>          history.pushState(null, "", $.url_old)
Valenta answered 29/3, 2012 at 10:8 Comment(0)
L
-2

Edit: Please see clime's answer below - It appears my answer is no longer correct.


Since the point of PJAX (pushState AJAX) is updating the url, I don't think there is a way to disable it. If updating the url isn't what your after you may just want to be using standard AJAX? (essentially use JQuery to perform an ajax get of a given path, then shove the contents in to a container of your choice)

The "replace" option in the JQuery PJAX script simply toggles between using "replaceState" & "pushState" to update a pages url.

Sorry i couldn't be of more help.

Lingle answered 28/3, 2012 at 17:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.