2013-04-10 132 views
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中正確引用。

+0

你確定你有jQuery來源?你是否收到任何控制檯錯誤消息? – smerny 2013-04-10 12:48:18

+0

此外,稍微OT,但它最好分開你的JavaScript ...而不是'onclick',你可以有一個描述性的ID,如'unbanButton',然後綁定你的代碼到該按鈕ID上的單擊事件。 – smerny 2013-04-10 12:51:14

回答

3

存在語法錯誤。 A )在這裏丟失

if (result.contains("Error:")){ 
       alert(result); 
}