最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - $.get is not a function - Stack Overflow

programmeradmin2浏览0评论

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

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);
        });
    });
});
Share Improve this question edited Nov 10, 2016 at 10:33 George Kagan 6,1248 gold badges49 silver badges50 bronze badges asked Nov 10, 2016 at 10:32 LeagisLeagis 1751 gold badge5 silver badges14 bronze badges 1
  • 4 I'm pretty sure the slim releases of jQuery 3 do not include the AJAX routines. Use the full release instead. – Frédéric Hamidi Commented Nov 10, 2016 at 10:35
Add a comment  | 

2 Answers 2

Reset to default 20

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/

Can you please try with any other version of jQuery instead of slim version? Like this CDN: https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js

May be ajax utilities are not available in slim version.

发布评论

评论列表(0)

  1. 暂无评论