-1

I use Symfony 5, but I can not make an AJAX call because it says that "$.ajax is not a function". I installed jQuery using composer require components/jquery and it does not work. I took the jquery directory from /vendor/components and I pasted it into the public directory, into a directory called "assets" and then I tried to include it with:

<script type="text/javascript" src="{{asset('assets/jquery/jquery.js')}}">

But nothing works. The script is:

<script type="text/javascript">
    let id = 1;
    $(document).ready(function() {
            $.ajax({
                url: "/getBuildingDetails",
                type: "GET",
                data: id,
                success: function (data) {
                    console.log(data);
                },
                error: function () {
                    console.log("Something went wrong");
                }
            });
        }
    );
</script>

I searched the error and the only thing was to change jquery.slim.min.js to jquery.min.js, but I already use jquery.min.js(at least I am trying to use it...). I tried with the cdn, but nothing works. I am new, I don't have experience... Do you have a video or an article that can help me? Thank you!

7
  • try to inspect element the existing error page via your browser (F12), then you will see the jquery url, right click on that, and press open link on new tab, you will see where the link goes Commented Jun 25, 2020 at 11:18
  • Ok, I will try. Thank you! Commented Jun 25, 2020 at 11:20
  • I tried it but I don't understand why $.ajax is not recognized as a function... What am I doing wrong? Commented Jun 25, 2020 at 11:26
  • 1
    Data should be an object. Try " data: {id : id} " Commented Jun 25, 2020 at 11:34
  • 1
    Does this help you out? stackoverflow.com/questions/12007911/… Commented Jun 25, 2020 at 12:32

1 Answer 1

0

Previously people have experienced issues with self closing tags...try below:

<script src="{{ asset('assets/jquery/jquery.js') }}" type="text/javascript" ></script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.