【问题标题】:jQuery script was attached multiple times and mixed up with DevExpress scriptsjQuery 脚本多次附加并与 DevExpress 脚本混合
【发布时间】:2018-12-04 02:13:51
【问题描述】:

我使用 jQuery UI Draggable 插件对 MVC 网格中的项目重新排序。但是我收到错误“jQuery 脚本被多次附加并与 DevExpress 脚本混合。”

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<script>
    var jq112 = jQuery.noConflict(); //
</script>

我在 index 和 web.config 设置中使用了上面的代码,如下所示。

<settings rightToLeft="false" embedRequiredClientLibraries="true" doctypeMode="Xhtml" />

【问题讨论】:

  • 能否提供web.config内容?我确定您在使用嵌入式脚本资源时使用&lt;script&gt; 标记多次加载 jQuery 脚本,因此我需要检查 web.config 以了解可能的第三方资源配置。
  • 您使用的是哪个 DevExpress 版本?检查 web.config 中是否使用了&lt;section name="resources" ...&gt;,然后由于 embedRequiredClientLibraries="true" 存在,尝试将其值设置为 false 并手动注册 jQuery 和 jQuery UI 脚本。
  • 我们使用的是 18.1.3。我不愿意将 embedRequiredClientLibraries="true" 更改为 false,因为这可能会影响其他控件。 web.config 中也没有使用

标签: jquery asp.net-mvc devexpress devexpress-mvc


【解决方案1】:

听起来问题是因为这个CDN脚本定义,它实际上在相应的视图页面中注册了单独的jQuery副本,而自动脚本注册功能仍然启用并导致资源冲突:

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

请注意,某些 DevExpress 扩展(GridViewPivotGridReportsCharts 等)需要外部客户端 JS 库才能正确使用其功能,并在 @987654330 内部启用某些设置时自动注册@ 文件(最引人注目的是在 &lt;resources&gt; 部分)。这里解释一下为什么启用脚本注册,取自knowledge base

客户端资源在添加时自动添加到 Web.config 文件中 一个 DevExpress Web 控件到您的应用程序使用 DevExpress 模板库。在这种情况下,所有必要的客户端库 会自动传递给客户端。

如果您想手动注册 jQuery 库,请尝试删除 web.config 中的自动脚本注册功能(有关详细信息,请参阅下面的参考资料)。

参考资料:

Script Registration Issues

How to register DevExpress scripts with external client libraries that use jQuery

Embedding Third-Party Libraries

【讨论】:

    猜你喜欢
    • 2015-07-08
    • 1970-01-01
    • 2011-06-14
    • 1970-01-01
    • 2012-11-18
    • 1970-01-01
    • 2015-10-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多