Why Is My JQuery Plugin Causing A Cannot Read Property 'length' of Undefined?

耗尽温柔 提交于 2019-12-10 03:38:22

问题


I kind of feel bad asking yet another Cannot Read Property 'length' of Undefined question, but no online (SE or otherwise) answers are in any way relating to my problem at hand.

I have tried my best to narrow down why this script error is occurring for my situation, but I am at a loss.

If I exclude this tag in the page, the error ceases to show up:

<script src="~/Plugins/jquery-ui-1.10.3.drag-drop.min.js" type="text/javascript"></script>

All that the jquery-ui-1.10.3.drag-drop.min.js file is is a jquery-custom file I renamed, that includes jquery draggable, droppable, and sortable.

I was sure that the error was caused by some script I wrote, but as I have just begun to test this out, I didn't have much script to 'comment out', and when I did so, it, to my befuddlement, didn't get rid of the error. The only way I have found so far to get rid of the error is to exclude the plug-in altogether, which I obviously wouldn't be able to use if I did.

The error in full as seen in Chrome's debugger:

Uncaught TypeError: Cannot read property 'length' of undefined      jquery-1.9.1.min.js:3
b.extend.each                                                       jquery-1.9.1.min.js:3
e.widget                                                            jquery-ui-1.10.3.drag-drop.min.js:6
(anonymous function)                                                jquery-ui-1.10.3.drag-drop.min.js:6
(anonymous function)                                                jquery-ui-1.10.3.drag-drop.min.js:6

The problem is (as it is with most errors like this) that I can't track down why this is causing an error, even if no code is written to even make use of this plug-in yet.

I am using jquery-1.9.1.min.js and the jquery-migrate-1.2.1.min.js files.

Truth is, I could ignore this error, as it doesn't really break anything, and the dragging, dropping, and sortable features all seem to work fine and as expected. I just think it is ugly to have script errors in your page, and as I have never tolerated them in the past, I didn't really want to start tolerating them now.

Am I barking up the wrong tree? Does the error not point to my drag-drop file? What can I do to help narrow this error down?

Please let me know if there is any more information I can supply that would help.

AS REQUESTED-<script> tags as they appear in the <head> Tag:

<script src="~/Resources/jquery-1.9.1.min.js" type="text/javascript"></script>
<script src="~/Resources/jquery-migrate-1.2.1.min.js" type="text/javascript"></script>
<script src="~/Plugins/jquery.maskedinput.min.js" type="text/javascript"></script>
<script src="~/Plugins/jquery-ui.min.js" type="text/javascript"></script>
<script src="~/Plugins/accounting.min.js" type="text/javascript"></script>
<script src="~/Plugins/jquery.autoellipsis-1.0.10.min.js" type="text/javascript"></script>
<script src="~/Plugins/jquery-ui-1.10.3.drag-drop.min.js" type="text/javascript"></script>
<script src="~/Scripts/PluginConfigurations.js" type="text/javascript"></script>
<script src="~/Scripts/main.js" type="text/javascript"></script>
<script src="~/Scripts/EditPages.js" type="text/javascript"></script>

回答1:


As @Pete has helped you identify, it is indeed caused by duplicating your jQuery UI core scripts. Load just them once, and your 'length of Undefined' issue will go away.




回答2:


As @Pete has helped you identify, it is indeed caused by duplicating your jQuery UI core scripts. Load just them once, and your 'length of Undefined' issue will go away.

Including below file twice,will cause this issue.

jquery.ui.core.min.js

Make sure you have included only once.



来源:https://stackoverflow.com/questions/18699968/why-is-my-jquery-plugin-causing-a-cannot-read-property-length-of-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!