我可以在同一个文件中包含 jQuery 和 AJAX 吗?这会冲突吗?
我可以在同一个文件中包含 jQuery 和 AJAX 吗?这会冲突吗?
我试图在 Magento GO 模板中包含 jQuery,但是当我上传并在模板中包含 jQuery 时,下拉菜单/等。停止工作。所有链接仍然工作正常,但下拉菜单和其他类似功能停止工作...
我相信这可能是因为 Magento 在其托管解决方案中包含了 AJAX...?
Can I include jQuery and AJAX in the same file? Would this conflict?
I am attempting to include jQuery with a Magento GO template, but when I upload and include jQuery in the template, the drop down menus/etc. stop working. The links all still work fine, but the dropdown menus, and other similar functionality stop working...
I believe this may be because Magento includes AJAX in the hosted solution on their end..?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
jQuery 代码的第一行需要是:
noConflict 函数取出了很多内容导致跨库错误。
The first line of your jQuery code needs to be:
The noConflict function takes out a lot of what causes cross-library errors.
不会,将 jQuery 与另一个使用 AJAX 的库一起使用不会导致任何冲突。
可能导致冲突的是 jQuery 库使用
$
标识符。如果其他代码也使用它,它们将无法一起工作,除非您使用 noConflict jQuery 中的方法。No, using jQuery along with another library that uses AJAX does not cause any conflicts.
What can cause a conflict is that the jQuery library uses the
$
identifier. If the other code is also using that, they won't work togehter unless you use the noConflict method in jQuery.Magento 默认包含 Prototype。强烈建议您不要添加 jQuery,除非无法避免。 jQuery 提供的几乎所有功能也可以在 Prototype/Scriptaculous,它只是不像 jQuery 那样流行(和/或营销良好)。
正如其他答案所建议的,您需要将 jQuery 置于
noConflict
模式。您会发现您可能仍会遇到其他问题,但这只是一个开始。Magento includes Prototype by default. It's strongly recommended that you do NOT add jQuery unless it cannot be avoided. Pretty much any functionality that jQuery provides is also available in Prototype/Scriptaculous, it's just not as popular (and/or well marketed) as jQuery.
As the other answers have suggested, you need to put jQuery into
noConflict
mode. You will find that you might still encounter other issues, but it's a start.