2015-08-29 158 views
0

我想用jQuery學習ajax,但我的腳本似乎不工作 我用表單來查看script.php文件是否有問題,但它工作正常精細。 當我點擊sendAjax按鈕時,什麼也沒有發生。我檢查Firefox上的開發工具中的網絡選項卡,看起來沒有任何東西發送。 我也嘗試發送數據json樣式但不工作{'data':'Data'} 即使我在php腳本上回顯某些內容也不起作用。 我認爲這只是一個愚蠢的錯誤,但因爲這是我的第一個ajax腳本,我很難找到它Post ajax請求沒有達到php

這是我的腳本。 index.html的jQuery腳本

$(document).ready(function() { 
    $("#sendAjax").click(function() { 

     $.ajax({ 
      type: 'POST', 
      url: "script.php", 
      cache: false, 
      data: { 
       dataStr: 'Content' 
      }, 
      succes: function (response) { 
       alert("merge"); 
      } 


     }); 
    }); 
}); 

index.html的HTML

<div id='container'> 
    <form action='script.php' method='POST'> 
     <input type='text' name='username' id='username' placeholder="name"> 
     <input type='password' name='password' id='password' placeholder="password"> 
     <input type="submit" name='button' value="SendForm" id='button'> 
    </form> 
    <button id='sendAjax'>Send</button> 
</div>  

的script.php

<?php 
    if(isset($_POST)){ 
     var_dump($_POST); 
    } 
+2

也許成功而不是成功? – Bernhard

+0

其錯字。 'succes' – RRK

回答

0
succes: function (response) { 
    alert("merge"); 
} 

更改爲

success: function (response) { 
    alert("merge"); 
}