Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$.get is not a function

I want to get some data over JS and therefore I "develop" a small script. Actually I haven't worked with JS/JQuery for a long time and now I'm facing a very basic problem. I tried to replace the $ with jQuery but I got the same error.

HTML

<html>
<head>
    <script type="text/javascript" src="jquery-3.1.1.slim.min.js"</script>"></script>
    <script type="text/javascript" src="main.js"</script>"></script>
</head>
<body>
    <button>Test</button>
</body>

JS

jQuery(document).ready(function(){
    jQuery("button").click(function(){
        jQuery.get("mydomain", function(data, status){
            alert("Data: " + data + "\nStatus: " + status);
        });
    });
});
like image 746
Leagis Avatar asked Jan 30 '26 03:01

Leagis


1 Answers

You are referencing jQuery Slim, which doesn't include (among other things) the Ajax functions such as .get().

You need to reference the full version of jQuery instead.

See this link for more a detailed description of what is and is not included in the Slim build: https://blog.jquery.com/2016/06/09/jquery-3-0-final-released/

like image 129
ADyson Avatar answered Jan 31 '26 19:01

ADyson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!