'$ .md5的神秘面纱不是一个功能' [英] The mystery of '$.md5 is not a function'
问题描述
我有一个使用jQuery.MD5库的js代码。它在我的服务器上运行良好:
I have a js code that uses jQuery.MD5 library. It works perfectly on my server:
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://example.com/static/js/jquery.md5.js"></script>
</head>
<body>
<script>
// my code goes here (declaring variables and functions)
var code = $.md5('mystring');
// and a little more code
</script>
</body>
然后我将它上传到网络应用程序(我无法控制),这使它看起来像这个并将其放入iframe:
But then I upload it to a web application (which I cannot control), that makes it look like this and puts it into an iframe:
<head>
<script>
// some extra variables are declared here
// double-checked that nothing here can break my code
</script>
</head>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://example.com/static/js/jquery.md5.js"></script>
<script>
// some code
var code = $.md5('mystring');
// some code
</script>
</body>
此代码开始给我 $。md5不是函数
错误。奇怪的事情。尝试清除缓存,将jquery.md5.js代码直接放入我的,没有任何作用。
And this code starts giving me the $.md5 is not a function
error. Strange thing. Tried clearing the cache, putting jquery.md5.js code directly into mine, nothing works.
请注意所有代码都在我的机器上运行,所以必须我的JS没有问题。
更新:有问题的代码行为似乎是不可预测的,这意味着有时它可以正常工作而无需更改。
可能出错?
推荐答案
Hm ...这有点令人尴尬,但问题出在jQuery上。我在iframe中包含的那个与页面中包含的那个冲突了。不知何故,这导致我的$ .md5函数在其代码结束后隐藏。
Hm... That's a little embarrassing, but the problem was in jQuery. The one I included in my iframe conflicted with the one included in the page. Somehow this lead to "hiding" my $.md5 function after its code's end.
是的,我知道,很明显jQuery可能会导致问题。
And yeah, I know, it was quite obvious that jQuery could cause problems.
这篇关于'$ .md5的神秘面纱不是一个功能'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!