get is not a function

Начнем использовать JQuery ? Но вначале у вас может возникнуть тысячи вопросов и ошибок, одна из которых — TypeError: $(. ) is not a function — из-за чего она возникает давайте разбираться. в интернете четкого ответа в первой десятке точно нет (по яндексу).

Ошибка в консоли TypeError: $(. ) is not a function возинкает в случае, когда вы неправильно или своеобразно определяете функцию, к примеру в этом случае может она возникнуть:

$(function()<
var el = document.getElementById(«some_id»);
$(el).css(‘border’,’1px solid red’);

Решение — написать следующим образом:

$( document ).ready(function()<
var el = document.getElementById(«some_id»);
$(el).css(‘border’,’1px solid red’);

Ну вот такая бяка, в принципе верхний вариант работает, но ошибка покоя не дает).

А вообще можешь писать так:

var el = document.getElementById(«some_id»);
$(el).css(‘border’,’1px solid red’);

Но только в этом случае вызов файла с библиотекой jquery и подключение файла js ставь вниз файла, в котором происходит подключение. А все дело в методе ready() библиотеки JQuery

I’m having a problem doing something very basic in jQuery. Can someone tell me what I’m doing wrong exactly?

If I run the code below, the function $.get seems to be missing (getJSON and others missing too). But $ itself and other functions do exist, so I know JQuery is loading.

Any ideas would be much appreciated.

Edit: here is some additional info:

5 Answers 5

The $ variable you have is from Prototype-js, because you are using the jQuery.noConflict method.

That method will restore the $ variable back to whichever library first implemented it.

You should use the jQuery methods on the jQuery global object directly, eg.:

Or you can define another shorter variable as alias if you want:

I want to get some data over JS and therefore I «develop» a small script. Actually I haven’t worked with JS/JQuery for a long time and now I’m facing a very basic problem. I tried to replace the $ with jQuery but I got the same error.

2 Answers 2

You are referencing jQuery Slim, which doesn’t include (among other things) the Ajax functions such as .get() .

You need to reference the full version of jQuery instead.

Оцените статью