2

I have below js function, I need to call /print2 function without clicking any buttons. I tried to write ajax to that. By the way, I am newer in ajax and js.

Where is the problem ı could not see ?

Thank you...

<script type="text/javascript" >
     function plot() {


    $.ajax({
        url: '/print2',
        success: function(data) {
            console.log('get info');

            $('#description').html(data['description']);
        }
    });


}

   plot()
</script>

It says

(index):30 Uncaught ReferenceError: $ is not defined at plot ((index):30) at (index):38

Where is the problem ?

Edit

$(document).ready(function () {
  //your code here
});

I wrapped my function with this code. As it stated here JQuery - $ is not defined

However, I it is not solve my problem.

4
  • 2
    Are you including jQuery...? Commented Sep 18, 2019 at 14:32
  • Possible duplicate of JQuery - $ is not defined Commented Sep 18, 2019 at 14:33
  • how can I do that ? Commented Sep 18, 2019 at 14:35
  • I did it stackoverflow.com/questions/2194992/jquery-is-not-defined and add this $(document).ready(function () { //your code here }); Commented Sep 18, 2019 at 14:37

1 Answer 1

1

It looks like you do not have jQuery. To get jQuery you include the following script at the end of the body tag in your HTML.

<script
  src="https://code.jquery.com/jquery-3.4.1.min.js"
  integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
  crossorigin="anonymous"></script>

make sure it is before this closing tag below.

</body>
Sign up to request clarification or add additional context in comments.

8 Comments

@ozer jQuery is a JavaScript library - think of it as an "extension" to JavaScript. All references to $ in your code are trying to reference jQuery functions, but without including jQuery, you can't use jQuery functions.
@ozer Ajax is built into jQuery. You can not use one without the other. This script tag tells the browser to load jQuery into your page. Without it, you will not be able to use any jQuery functionality. If the answer fixed our issue please select it as closed to let others know that the issue has been solved.
@thatguy "You can not use one without the other. " - this is incorrect. You can certainly use jQuery without AJAX, and you can certainly use AJAX without jQuery.
@TylerRoper True, and I can see your issue with the comment and understand where you are coming from. My comment was more directed towards the $.ajax syntax the OP is using while also not trying to confuse or overwhelm a newer developer. Keeping it simple in the beginning is key to learning. Deep dives into the technologies and semantical differences will only confuse and deter someone who is just learning.
@TylerRoper makes sense. I will be sure to be more explicit in the future.
|

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.