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

javascript - Uncaught TypeError: $.ajax is not a function - Stack Overflow

programmeradmin0浏览0评论

I'm making a small game project with a leaderboard table.

I'm trying to get the leaderboard from a mysql database to display using jQuery ajax and PHP but its giving me an error message.

My syntax seems to look fine so I'm not sure what the problem is.

$("#leader-btn").click(function() {

    $.ajax({
        type: "GET",
        url: "leaderboard.php",
        dataType: "html",
        success: function(response) {
            $("#leaderboard-box").html(response);
            $("#leaderboard-box").css("display","block");
        }

    });

});

I'm making a small game project with a leaderboard table.

I'm trying to get the leaderboard from a mysql database to display using jQuery ajax and PHP but its giving me an error message.

My syntax seems to look fine so I'm not sure what the problem is.

$("#leader-btn").click(function() {

    $.ajax({
        type: "GET",
        url: "leaderboard.php",
        dataType: "html",
        success: function(response) {
            $("#leaderboard-box").html(response);
            $("#leaderboard-box").css("display","block");
        }

    });

});
Share Improve this question edited Dec 2, 2016 at 18:53 Jed Fox 3,0255 gold badges30 silver badges38 bronze badges asked Dec 2, 2016 at 18:23 Zubair AliZubair Ali 491 silver badge3 bronze badges 12
  • 3 Have you included jQuery, and also have you wrapped this in $(document).ready(function() {? – Tricky12 Commented Dec 2, 2016 at 18:25
  • 1 @Tricky12 Event handler declarations aren't supposed to be wrapped in $(document).ready(). – Xavier J Commented Dec 2, 2016 at 18:28
  • 1 @codenoir All jQuery needs to be wrapped in it, otherwise it may be declared before jQuery has loaded, and will therefor not be attached to the DOM. Hence why he would see a "function does not exist" error. It tries to call the function before jQuery has loaded. – Tricky12 Commented Dec 2, 2016 at 18:33
  • 1 @Tricky12 not quite, but you keep on thinking that. – Xavier J Commented Dec 2, 2016 at 18:34
  • 2 One other thing to try is jQuery.ajax instead of $.ajax. If you have more libraries included than just jQuery, $ could potentially be aliased to something else in your code. – Tricky12 Commented Dec 2, 2016 at 19:03
 |  Show 7 more ments

1 Answer 1

Reset to default 10

I had the same problem. It turned out that I was using jQuery slim instead of the full library.

发布评论

评论列表(0)

  1. 暂无评论