Why Is My JQuery Plugin Causing A Cannot Read Prop

2019-04-24 22:49发布

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>

2条回答
欢心
2楼-- · 2019-04-24 23:24

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.

查看更多
太酷不给撩
3楼-- · 2019-04-24 23:27

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.

查看更多
登录 后发表回答