gelviis
gelviis

Reputation: 458

How to get PJAX to work on a button and a link?

I have a number of buttons like this:

<button data-pjax class="btn btn-inverse" type="button" onclick="location.href='http://mybuttonurl.com'">my button</button>

And a number of urls like this:

<a data-pjax href="http://mylinkurl.com">My url</a>

I want PJAX to work on both the buttons and the links. This code works for the links:

$(document).pjax('[data-pjax] a, a[data-pjax]', '#pjax-content');

So does this:

$(document).pjax('a', '#pjax-content');

I can't seem to get it working for buttons and links. Even this won't work for buttons alone:

$(document).pjax('button', '#pjax-content');

How can I get this to work?

Note: when I say "won't work" it means the page does a full refresh rather than just load the HTML content into #pjax-content.

Upvotes: 0

Views: 1013

Answers (1)

gelviis
gelviis

Reputation: 458

As I am using Twitter Bootstrap I ended up replacing the button with a link:

<a data-pjax class="btn btn-inverse" type="button" href='http://mybuttonurl.com'>my button</a>

I believe this is a better way to do what I was trying to do + PJAX works cross browser this way

Upvotes: 1

Related Questions