So my code looks like this http://jsfiddle.net/qBZMh/4/
Now, on this it won't add the class "active" because it can't find the requested file, for me it finds the file but it won't run the file. My PHP-file look like this:
<?php
$time = time();
mysql_query("INSERT INTO friends
(userid, userid2, `type`, `date`) VALUES
('1', '2', '1', '$time' )") or die(mysql_error());
?>
jQuery:
$(document).ready(function () {
$("#addfriend").click(function () {
$.ajax({
url: "snippets/profile_addfriend.php",
context: document.body
}).done(function () {
$("#addfriend").addClass("active");
});
});
});
$(document).ready(function () {
$("body").on({
ajaxStart: function () {
$(this).addClass("loading");
},
ajaxStop: function () {
//$(this).removeClass("loading");
}
});
});
There should be variables instead of numbers but just to see if it actually runs I have removed that.
So, the problems are:
It finds the PHP-file but it won't run the script.
It doesn't show a loading bar, I might have understood this wrong but I want it so my button gets replaced by the loading bar and then appears again when the script have been executed.