我已经在一段代码上工作了几天但是我不知道怎么把这个值传递给我的数据库.基本上我想要实现的是,一旦用户点击"收集硬币"按钮,它就将值1传递给我的数据库.每天中午12点,"dailyfree"列被MySQL事件重置为0,因此第二天用户可以再次单击该按钮,因为数据库中"dailyfree"的值再次为0.我仍然不希望用户能够在重置数据库中的值之前单击"收集硬币".问题是,一旦用户点击按钮,它就会给他免费的硬币,但值1不会传递给数据库.单击按钮后,"dailyfree"列仍为0.有谁知道那是为什么?
仅供参考:我对编码很新!
这就是我现在正在使用的内容.
使用Javascript:
function free(){
var str = "username";
var term = "searched_word";
var index = str.indexOf(term);
if (index != -1) {
var daily = 1;
$.ajax({
url:"/free?daily="+daily,
success:function(data){
try{
data = JSON.parse(data);
console.log(data);
if(data.success){
bootbox.alert("Success! You've claimed 100 free credits!");
}else{
bootbox.alert(data.error);
}
}catch(err){
bootbox.alert("Javascript error: "+err);
}
},
error:function(err){
bootbox.alert("AJAX error: "+err);
}
});
}
else {
bootbox.alert("Your username does not contain the searched_word!");}
}
function disDelay(obj){
obj.setAttribute('disabled','disabled');
setTimeout(function(){obj.removeAttribute('disabled')},86400)
}
Run Code Online (Sandbox Code Playgroud)
按钮本身
<div class="text-right">
<button class="btn btn-success btn-block" …Run Code Online (Sandbox Code Playgroud)