sevzas
sevzas

Reputation: 801

While using jquery-pjax how can I force one link to do full page load

My application uses jquery-pjax and it works fine for all pages except one where the content contains some < script > tags which are not executed because jquery-pjax simply places the returned content in an element without executing the elements that are inside the content.

I want to work around this. When a user tries to load this page by clicking on it's , I simply want to bypass the jquery-pjax functionality and do a full page load. How can I accomplish this? Can I somehow indicate this on the element?

I see there are multiple flavors of jquery-pjax out there on github. I'm using the "defunkt" version here . There is also the yiisoft version here . The Yiisoft version was forked from the defunkt version.

I am using the defunkt version, but the yiisoft version appears to have a built-in feature to suppress pjax functionality for a link that is describe in my second answer.

Upvotes: 0

Views: 453

Answers (3)

sevzas
sevzas

Reputation: 801

The two answers I gave previously require changing the < a > element of a page that does not work correctly with pjax. The shortcoming of this approach is that it might be difficult to find every < a > on your site that links to a particular page.

An alternative method that runs server-side and does not require changes to < a > elements is to remove the header tag "X-PJAX" at the earliest opportunity when preparing a response to affected pages. This is the implementation of this idea for Asp.Net MVC:

Create an extension method:

Imports System.Runtime.CompilerServices

Module PjaxExtension

    <Extension()>
    Public Sub DisablePjax(ByVal c As Controller)
        c.Request.Headers.Remove("X-PJAX")
    End Sub

End Module

In your controller at the top:

Imports MyWebSite.PjaxExtension

In your action method in the controller:

DisablePjax()

Upvotes: 0

sevzas
sevzas

Reputation: 801

If you're using yiisoft jquery-pjax, you can add "data-pjax='0'" as an attribute to the < a > element to suppress pjax functionality. This feature is not offered in the defunkt version of pjax.

Upvotes: 0

sevzas
sevzas

Reputation: 801

One way to bypass jquery-pjax's functionality is to create the <a> element so that it uses the onclick() event to load a page instead of an href.

Link that uses jquery-pjax:

<a href="/page_url">Pjax Page</a>

Link that bypasses jquery-pjax:

<script language="javascript" type="text/javascript">
    function load_page() {
        window.location.href = "/page_url";
    }
</script>
<a onclick="load_page();">non-Pjax Page</a>

Upvotes: 1

Related Questions