admin管理员组文章数量:1306743
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
1 Answer
Reset to default 10I had the same problem. It turned out that I was using jQuery slim instead of the full library.
本文标签: javascriptUncaught TypeError ajax is not a functionStack Overflow
版权声明:本文标题:javascript - Uncaught TypeError: $.ajax is not a function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741821396a2399386.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论