1. 程式人生 > >JQuery九種與後臺互動資料的方法(ajax)

JQuery九種與後臺互動資料的方法(ajax)

      @{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <title>Index</title>
    <script src="../../Scripts/jquery-1.7.1.js"></script>
    <script src="../../Scripts/jquery.unobtrusive-ajax.js"></script>  @*隱式的表單驗證*@
    <script type="text/javascript">
        function afterSuccess() {
            alert('haha');
        };
    </script>
</head>
<body>
    <div>
       @{
           using (@Ajax.BeginForm("Index", new AjaxOptions()
           {
               Confirm = "咋樣啊 ……",
               HttpMethod = "Post",  // 非同步請求的方式
               OnSuccess = "afterSuccess",  // 成功後呼叫的回撥函式
               UpdateTargetId = "#resultDiv", // 成功後選擇改變的表單
               InsertionMode = InsertionMode.Replace 
           }))
           {
             <input type="submit" value="提交" />
           }
       }
  
    </div>
    <div id="resultDiv">
    </div>
</body>
</html>