Leagis Leagis - 29 days ago 14
Ajax Question

$.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);
});
});
});

Answer

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/