0
首先,我试图使用HTML元素(按钮),onClick,执行我有的JavaScript函数。该函数被称为Unban(玩家),它从我正在工作的某个东西中“解除”玩家。使用onClick与jQuery POST不起作用
元素看起来是这样的,
<button name="button" id="button" onclick="Unban('somebody')"/>
和JavaScript看起来像这样:
function Unban(player){
if (confirm("Are you sure you want to remove the ban on " + player + "?")){
$.post("actions/unban.php",{Player:player},function(result){
if (result.contains("Error:"){
alert(result);
}
else{
alert("You have unbanned " + player + "!");
}
});
}
}
的问题是:什么也没有发生在所有的时候我呼吁取消禁止(播放器)功能。我做了一些测试,没有$ .post就能正常运行,所以它必须与它相关。
PHP文件工作正常,功能正常。它也在$ .post中正确引用。
你确定你有jQuery来源?你是否收到任何控制台错误消息? – smerny 2013-04-10 12:48:18
此外,稍微OT,但它最好分开你的JavaScript ...而不是'onclick',你可以有一个描述性的ID,如'unbanButton',然后绑定你的代码到该按钮ID上的单击事件。 – smerny 2013-04-10 12:51:14