0

JQuery does not seem to work in my Symfony2 project.

I use these 2 snippets to test JQuery in a twig html file and none of them is working:

    {% block myJavascript %}
    <script type="text/javascript">

    if (typeof jQuery != 'undefined') {
        alert('hi'); }


     $(document).ready(function() {
        alert('hi');
     });
    </script>
    {% endblock %}

This code alone is working meaning that Javascript is working

     alert('hi');

I have in my app/resources/view/base.html.twig

         <link rel="javascript" href="{{ asset('bundles/etiennepsav/js/jquery-1.8.3.js') }}" type="text/javascript" media="all" />

Referring to the jQuery files located in :

   app/src/Etienne/Bundle/PsavBundle/Resources/Public/js/jquery-1.8.3.js

Any ideas what's wrong? Is there a special config to set?

1 Answer 1

6

Javascript needs a <script> tag not a <link> tag in order to load in a page

Sign up to request clarification or add additional context in comments.

7 Comments

I don't understand the downvote since this is a valid answer.
@j0k You are right! Is the question that should be downvoted! So I'll upvote the answer!
@JeanValjean well, so u consider that asking wether jquery can work with symfony and how is not a good question? being obvious to u doesnt mean it is obvious to everyone...every environment have their specificities...i dont find changing my title was particularely a good idea...that was not the question i have asked
@Matoeil You can edit your question if you want to change title and more! The title should be related to the problem and to the solution. In my perspective, the title was misleading and without a great sense, while now is more useful for the community!
@Matoeil About specificities, this is a community of programmers. The basis are expected to be known. A programmer should know that jQuery is just a Javascript library. Since Javascript is a client-side language that interacts with the server-side by means of http requests and that can receive strings from the server, one should imagine that each problem of the type you shown is merely due to a coding error in the "view".
|

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.