0

I have a follow button that implement ajax but it is returning Uncaught ReferenceError: $ is not defined so in other words it is not working, here I will leave the code please help.

prifile.html

    <a type="button" id="follow" role="button" href="{% url 'follow' post_owner.username %}">Follow</a>

    <script type="text/javascript">
        $("#follow").click(function(e){
            e.preventDefault();
            var href = this.href;
            $.ajax({
                url : href,
                success : function(response){
                    if(response["following"]){
                        $("#follow").html("Unfollow");
                    }
                    else{
                        $("#follow").html("Follow");
                    }
                }
            })
        })
    </script>
Juan Martin Zabala
  • 743
  • 2
  • 9
  • 29
  • 2
    The error means, when your code execute in browser, it could not find reference for $. It means, it could not find jquery before your code. Have you included jquery along with your js file on the page? Is jquery loading before your code? – Rajesh Dwivedi Jun 11 '20 at 01:00
  • 1
    You should include this tag in the head of your html `` – esteban21 Jun 11 '20 at 01:20

0 Answers0