Heim  >  Artikel  >  php教程  >  在Yii2中使用Pjax导致Yii2内联脚本载入失败的原因分析,yii2pjax

在Yii2中使用Pjax导致Yii2内联脚本载入失败的原因分析,yii2pjax

WBOY
WBOYOriginal
2016-06-13 08:44:511160Durchsuche

在Yii2中使用Pjax导致Yii2内联脚本载入失败的原因分析,yii2pjax

当我用defunkt/jquery-pjax载入Yii2的ActiveForm时发生一个错误,正常情况下是

ActiveForm的两个js应该先载入,而实际情况是

typeError:JQuery(...).yiiActiveForm is not a function。

在github的issues对这个问题已经讨论并得到了解决。

  Pjax首先通过html()执行内联的<script>,然后才通过executeScriptTags()执行带着src的<script>,所以导致找不到yiiActiveForm。Pjax作者拒绝使用JQuery.getScript()解决这个问题,因为安全原因函数使用eval不符合CSP (Content Security Policy)</script>

以上所述给大家介绍了在Yii2中使用Pjax导致Yii2内联脚本载入失败的原因分析的相关资料,希望对大家以上帮助!

您可能感兴趣的文章:

  • 从零开始学YII2框架(六)高级应用程序模板
  • 从零开始学YII2框架(五)快速生成代码工具 Gii 的使用
  • 从零开始学YII2框架(四)扩展插件yii2-kartikgii
  • 从零开始学YII2框架(三)扩展插件yii2-gird
  • 从零开始学YII2框架(二)通过 Composer 安装扩展插件
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn