@Radiss

Ошибка с jpuery: «$.get is not a function» — как решить?

script.js

spoiler

$(document).ready(function ($) {
        $(document).on('click', '.checkbox', function(){
                $(this).parent().addClass('completed');
                $(this).attr('disabled', true);

                uid = $(this).attr('data-uid');
                $.get("/api/complete/" + uid);
        });

        $(document).on('click', '.remove', function(){
                $(this).parent().remove();
        });
});



В консоли указывает на эту стр $.get("/api/complete/" + uid);

Uncaught TypeError: $.get is not a function
at HTMLInputElement. (script.js:7)
at HTMLDocument.dispatch (jquery-3.4.1.slim.min.js:2)
at HTMLDocument.v.handle (jquery-3.4.1.slim.min.js:2)
(anonymous) @ script.js:7
dispatch @ jquery-3.4.1.slim.min.js:2
v.handle @ jquery-3.4.1.slim.min.js:2


index.tpl
spoiler

<html>
  <head>
    <title>Задачи на день</title>
    <link rel="stylesheet" href="static/styles.css">

    <!--<script src="http://code.jquery.com/jquery-3.3.1.slim.min.js"></script>-->
        <script
  src="https://code.jquery.com/jquery-3.4.1.slim.min.js"
  integrity="sha256-pasqAKBDmFT4eHoN2ndd6lN370kFiGUFyTiUHWhU7k8="
  crossorigin="anonymous"></script>
    <script src="static/script.js"></script>
  </head>
  <body>
  <div class="container">
    <h1>Текущие задачи</h1>
    <ul id="todo-list">
    % for task in tasks:
      % if task.is_completed:
      <li class="completed">
        <input class='checkbox' data-uid={{ task.uid }} type='checkbox'
         disabled='disabled' checked='checked' />
      % else:
      <li>
        <input class='checkbox' data-uid={{ task.uid }} type='checkbox' />       {{ task }}
      % end
        {{ task }}
        <a class="remove" href="/api/delete/{{ task.uid }}">X</a>
        <hr/>
      </li>
    % end
    </ul>
    <!--<form id="todo-add">
      <input type="text" id="new-todo-description" class="form-control"/>
      <button class="add" type="submit">+</button>
    </form>-->
       <form action="/add-task" method="post">
      <input type="text" name="description"/>
      <button type="submit">+</button>
       </form>
  </div>
  </body>

</html>



server.py
spoiler

## server.py
from bottle import route, run, static_file, view, redirect, request


class TodoItem:
    def __init__(self, description, unique_id):
        self.description = description
        self.is_completed = False
        self.uid = unique_id

    def __str__(self):
        return self.description.lower()


tasks_db = {
    1: TodoItem("прочитать книгу", 1),
    2: TodoItem("учиться жонглировать 30 минут", 2),
    3: TodoItem("помыть посуду", 3),
    4: TodoItem("поесть", 4),
}

###
@route("/static/<filename:path>")
def send_static(filename):
    return static_file(filename, root="static")


@route("/")
@view("index")
def index():
    tasks = tasks_db.values()
    return {"tasks": tasks}


@route("/api/delete/<uid:int>")
def api_delete(uid):
    tasks_db.pop(uid)
    return redirect("/")


@route("/api/complete/<uid:int>")
def api_complete(uid):
    tasks_db[uid].is_completed = True
    return "Ok"

@route("/add-task", method="POST")
def add_task():
    desc = request.POST.description.strip()
    if len(desc) > 0:
       new_uid = max(tasks_db.keys()) + 1
       t = TodoItem(desc, new_uid)
       tasks_db[new_uid] = t
    return redirect("/")


###
run(host="127.0.0.1", port=8080)



Пробовал менять версию jquery, но без изменений
  • Вопрос задан
  • 346 просмотров
Решения вопроса 1
Stalker_RED
@Stalker_RED
src="https://code.jquery.com/jquery-3.4.1.slim.min.js"

В slim версии действительно нет такой функции.
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы