powered by simpleCommunicator - 2.0.59     © 2025 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / HTML, JavaScript, VBScript, CSS [игнор отключен] [закрыт для гостей] / Uncaught TypeError: jQuery is not a function
20 сообщений из 20, страница 1 из 1
Uncaught TypeError: jQuery is not a function
    #39843999
Ролг Хупин
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Приложение ASP.NET Core +ElectronNET

1. запускаю в VS как IISExpress - в броузере все работает
2. запускаю как приложение - пишет странные ошибки, типа
Uncaught TypeError: $ is not a function
at TreeMaintain (jsTreeIndex:126)
at jsTreeIndex:143

Я заменил $ на jQuery, получил:
Uncaught TypeError: jQuery is not a function
Заменил на вызов
var idtree2 = document.getElementById('treeview');
idtree2.jstree(...)

пишет jstree не найдена, хотя студия показывает даже подсказки какие есть вызовы и параметры.
В общем - не могу понять причину фигни.

Код: javascript
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
<script src='https://code.jquery.com/jquery-latest.js'></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.8/themes/default/style.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.8/jstree.min.js"></script>

<div id="treeview"> </div>
 <script>
 function TreeMaintain() {
            var idtree2 = document.getElementById('treeview');
            //alert('idtree2:' + idtree2);
            if (idtree2 != null) {
                //idtree2.jstree({
                $('#treeview').jstree({
                    "plugins": ["search", "wholerow"],
                    'core': {
                        'data': {
                            'url': function (node) {
                                return node.id === '#' ? "/Utility/GetRoot" : "/Utility/GetChildren/" + node.id;

                            },
                            'data': function (node) {
                                return { 'id': node.id };
                            }
                        }
                    }
                });
            }
        };
	TreeMaintain();		
 </script>		
...
Рейтинг: 0 / 0
Uncaught TypeError: jQuery is not a function
    #39844002
Фотография Konst_One
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
попробуй вызвать свою функцию с задержкой
...
Рейтинг: 0 / 0
Uncaught TypeError: jQuery is not a function
    #39844014
Ролг Хупин
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Konst_Oneпопробуй вызвать свою функцию с задержкой

как это сделать?
...
Рейтинг: 0 / 0
Uncaught TypeError: jQuery is not a function
    #39844019
Фотография Konst_One
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
...
Рейтинг: 0 / 0
Uncaught TypeError: jQuery is not a function
    #39844023
Ролг Хупин
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Konst_OnesetTimeout

https://learn.javascript.ru/settimeout-setinterval

сделал таймаут, не помогает, сыпется, **ка....

Код: javascript
1.
2.
3.
4.
5.
6.
7.
8.
9.
Uncaught TypeError: Cannot read property 'fn' of undefined
    at util.js:55
    at bootstrap.min.js:6
    at bootstrap.min.js:6
jsTreeIndex:154 Uncaught TypeError: jQuery is not a function
    at jsTreeIndex:154

Uncaught TypeError: jQuery(...).jstree is not a function
    at TreeMaintain (jsTreeIndex:129)
...
Рейтинг: 0 / 0
Uncaught TypeError: jQuery is not a function
    #39844048
Фотография Konst_One
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
jQuery is not a function - проблема в этом скорее всего
...
Рейтинг: 0 / 0
Uncaught TypeError: jQuery is not a function
    #39844050
Фотография Konst_One
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Код: sql
1.
<script src='https://code.jquery.com/jquery-latest.js'></script>



подключи скаченный скрипт с директории своего сайта в head страницы своего layout-а (или где там ты его юзаешь) и проверь будет ли работать jquery
...
Рейтинг: 0 / 0
Uncaught TypeError: jQuery is not a function
    #39844056
Ролг Хупин
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Konst_One jQuery is not a function - проблема в этом скорее всего


да, это проявление, а причина х.поймёшь где, все вроде нормально. Сейчас попробую минимизнуть страницу до предела, подключить скрипт локально
...
Рейтинг: 0 / 0
Uncaught TypeError: jQuery is not a function
    #39844059
Фотография Konst_One
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
...
Рейтинг: 0 / 0
Uncaught TypeError: jQuery is not a function
    #39844061
Фотография Konst_One
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Install jQuery into your project using the following command in the node command prompt :

Код: sql
1.
npm install jquery --save


Now add the following code inside a script tag (or a js file):

Код: sql
1.
<script>window.$ = window.jQuery = require('jquery');</script>


You need to simply declare the jQuery and $global variables with the value (the library itself) returned for the require method.
...
Рейтинг: 0 / 0
Uncaught TypeError: jQuery is not a function
    #39844098
Ролг Хупин
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Konst_OneInstall jQuery into your project using the following command in the node command prompt :

Код: sql
1.
npm install jquery --save


Now add the following code inside a script tag (or a js file):

Код: sql
1.
<script>window.$ = window.jQuery = require('jquery');</script>


You need to simply declare the jQuery and $global variables with the value (the library itself) returned for the require method.

это сделал, не помогло.
...
Рейтинг: 0 / 0
Uncaught TypeError: jQuery is not a function
    #39844108
Фотография Konst_One
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
после этого скрипта

Код: sql
1.
2.
<script>window.$ = window.jQuery = require('jquery');</script>
 


по прежнему недоступна $ ?
...
Рейтинг: 0 / 0
Uncaught TypeError: jQuery is not a function
    #39844112
Ролг Хупин
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Такой файл получился
При запуске как приложение дает ошибку

авторUncaught TypeError: jQuery is not a function
at TreeMaintain (jsTreeIndex:51)


Это строка jQuery('#treeview').jstree({

Код: html
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
@{
    ViewData["Title"] = "jsTreeIndex";
}

@{
        Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <script src='https://code.jquery.com/jquery-latest.js'></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.8/themes/default/style.min.css" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.8/jstree.min.js"></script>
    <script src='~/lib/bootstrap/dist/js/bootstrap.min.js'></script>
</head>
<body>
    

    

    

    <h1>HTML demo</h1>

    <div id="containerParent">
        <h1>Tree container</h1>
        <div id="container">
            <ul>
                <li data-jstree='{ "opened" : true }'>
                    Rootello node
                    <ul>
                        <li data-jstree='{ "selected" : true }'>Kind node 1</li>
                        <li>Kind node 2</li>
                        <li>Kind node 3</li>
                    </ul>
                </li>
            </ul>
        </div>
        <h1>Tree2 container</h1>
        <div id="container2"> </div>
        <h1>TreeView container</h1>
        <div id="treeview"> </div>
        <h1>Tree3 container</h1>
        <div id="container3"> </div>
    </div>

    <script>window.jQuery = window.$ = require('jquery');</script>
    <script>window.jQuery = window.$ = module.exports</script>

    <script>
        if (typeof $ == 'undefined') {
            var $ = jQuery;
        }
        //$
        function TreeMaintain(divTree) {
            var idtree2 = document.getElementById('treeview');
            //alert('idtree2:' + idtree2);
            if (idtree2 != null) {
                //idtree2.jstree({
                jQuery('#treeview').jstree({
                    "plugins": ["search", "wholerow"],
                    'core': {
                        'data': {
                            'url': function (node) {
                                return node.id === '#' ? "/Utility/GetRoot" : "/Utility/GetChildren/" + node.id;

                            },
                            'data': function (node) {
                                return { 'id': node.id };
                            }
                        }
                    }
                });
            }
        };

        setTimeout(TreeMaintain, 1000, 'treeview');

        jQuery(function () {
            $.noConflict();
            $('#container').jstree();
        });

            $(function () {
            //$('#container').jstree({
            //var idtree = document.getElementById('container');
            //alert('idtree:' + idtree);
            //if (idtree != null) {
            //  idTree.jstree({
            $('#container2').jstree({
                'core': {
                    'data': [
                        {
                            "text": "Koreshok node", "children": [
                                {
                                    "text": "Bratan node 1",
                                    "children": [
                                        { "text": "Bratan node 11" },
                                        { "text": "Bratan 21" },
                                        { "text": "Bratan node 31" }
                                    ]
                                },
                                { "text": "Bratan 2" },
                                { "text": "Bratan node 3" }
                            ]
                        }
                    ]
                }
            });
            //  }
        });
    </script>
</body>
</html>
...
Рейтинг: 0 / 0
Uncaught TypeError: jQuery is not a function
    #39844116
Фотография Konst_One
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
внимательно читайте (ссылку на jquery вам не надо добавлять в head, нужно через require('./path/to/jquery') делать):
https://stackoverflow.com/a/37480521

возможно вы путь указали неправильный к бибилиотеки jquery (относительный путь внутри проекта)
...
Рейтинг: 0 / 0
Uncaught TypeError: jQuery is not a function
    #39844167
Ролг Хупин
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Konst_Oneвнимательно читайте (ссылку на jquery вам не надо добавлять в head, нужно через require('./path/to/jquery') делать):
https://stackoverflow.com/a/37480521

возможно вы путь указали неправильный к бибилиотеки jquery (относительный путь внутри проекта)

путь длолжен быть относительно какого фолдера?

Я убрал в хеаде, добавил внизу
Код: javascript
1.
    <script>window.$ = window.jQuery = require('~/lib/jquery/dist/jquery.min.js')</script>



у меня структура фолдеров такая:

Project
-Controllers
-Views
--test.cshtml
-wwwroot
--lib
---jquery
----dist (\jquery.min.js)
--css
---site.css
...
Рейтинг: 0 / 0
Uncaught TypeError: jQuery is not a function
    #39844176
Фотография Konst_One
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
wwwroot
...
Рейтинг: 0 / 0
Uncaught TypeError: jQuery is not a function
    #39844178
Фотография Konst_One
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
так пробуйте:
Код: sql
1.
<script>window.$ = window.jQuery = require('./lib/jquery/dist/jquery.min.js')</script>
...
Рейтинг: 0 / 0
Uncaught TypeError: jQuery is not a function
    #39844184
Фотография Konst_One
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
и этот скрипт нужно вставить до внедрения вендорских скриптов (бутстрап, дерево и тп)
...
Рейтинг: 0 / 0
Uncaught TypeError: jQuery is not a function
    #39844229
Ролг Хупин
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Konst_Oneи этот скрипт нужно вставить до внедрения вендорских скриптов (бутстрап, дерево и тп)

Это п-ц какой-то


Код: javascript
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
Uncaught TypeError: Cannot read property 'fn' of undefined
    at util.js:55
    at bootstrap.min.js:6
    at bootstrap.min.js:6
internal/modules/cjs/loader.js:686 Uncaught Error: Cannot find module './lib/jquery/dist/jquery.min.js'
Require stack:
- E:\MyProjects\_CrossPlatform\DbManager\DbManager\obj\Host\node_modules\electron\dist\resources\electron.asar\renderer\init.js
    at Module._resolveFilename (internal/modules/cjs/loader.js:683)
    at Function.Module._resolveFilename (E:\MyProjects\_Cross…-search-paths.js:43)
    at Function.Module._load (internal/modules/cjs/loader.js:601)
    at Module.require (internal/modules/cjs/loader.js:739)
    at require (internal/modules/cjs/helpers.js:14)
    at jsTreeIndex:41
jsTreeIndex:44 Uncaught ReferenceError: jQuery is not defined
    at jsTreeIndex:44
...
Рейтинг: 0 / 0
Uncaught TypeError: jQuery is not a function
    #39844230
Фотография Konst_One
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
сами выбрали такой , читайте доки, вот ещё совет от разработчиков

https://electronjs.org/docs/faq#i-can-not-use-jqueryrequirejsmeteorangularjs-in-electron
...
Рейтинг: 0 / 0
20 сообщений из 20, страница 1 из 1
Форумы / HTML, JavaScript, VBScript, CSS [игнор отключен] [закрыт для гостей] / Uncaught TypeError: jQuery is not a function
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]