Hi there,
I’m using Yii2’s PJAX to submit a form. On the first submission, everything works perfectly—the controller receives the request and renders a partial view as expected. However, on the second submission (without a page reload), the form submits in the normal way (full page reload) instead of using PJAX.
Has anyone encountered this issue before or know what might cause PJAX to stop working after the first submission?
Optional: Re-init JS plugins after PJAX loads (if you got any JS stuff):
$(document).on('pjax:end', function() {
// Re-init your scripts here if needed
});
Important!
Don’t replace the entire PJAX container ID ‘pjax-container’. Only update inside it.
Keep data-pjax=“true” on your form or PJAX won’t intercept submits.
This way, your form keeps that PJAX magic every time you submit, no full reloads.
That’s it — keep your PJAX alive like Rick keeps his portal gun charged. Good luck!