Skip to content

Inline registering of javascript during PJAX calls uses document.on('ready') instead of document.on('ready pjax:end') #8702

@sergeantjonas

Description

@sergeantjonas

I recently changed my application to use pjax requests, but today I stumbled upon an issue while using inline javascript ($this->registerJS). The javascript is not being executed as it's wrapped in a document.ready. After doing some digging it appears the root cause lies all the way in the web/View.php file.

Line 565 has the following:

$js = "jQuery(document).ready(function () {\n" . implode("\n", $this->js[self::POS_READY]) . "\n});";

It should be:

$js = "jQuery(document).on('ready pjax:end', function () {\n" . implode("\n", $this->js[self::POS_READY]) . "\n});";

But then even if no PJAX is being used the pjax:end will be there, although I don't think that causes issues, there is probably a cleaner fix (checking for the PJAX request header?)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions