Code Monkey home page Code Monkey logo

Comments (4)

cromulus avatar cromulus commented on May 20, 2024

Having the same problem. No javascript from the page called by pjax is executed.

Is this the expected behavior or a bug?

from jquery-pjax.

inspire22 avatar inspire22 commented on May 20, 2024

I'm pretty sure it's a bug with jquery/browsers... from what I've seen theres not much they can do about it. When jquery parses a html fragment that includes it won't run any scripts in it. You can't replace() out them in the success block either - it's already too late.

The only solution seems to be to move per-page scripts into a global handler that checks the location.url and executes the code for the page when it sees that url is the current one.... then you could call that function in your pjax success handler.

To make things even more fun, there's no way for the pjax success handler to be called on a "back button" trigger, though I've seen references to a global success function that might work that I can't find anywhere.

from jquery-pjax.

mybuddymichael avatar mybuddymichael commented on May 20, 2024

What worked for me was to place my jQuery code in a function, call it normally on document.ready (for non-pushState browsers), and then bind the function to pjax:end, i.e.:

$('body').bind 'pjax:end', mainFunction

from jquery-pjax.

josh avatar josh commented on May 20, 2024

We basically need to move everything to events.

See #29

from jquery-pjax.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.