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.