JQuery------$.ajax()的使用方法

菜鸟教程地址:

http://www.runoob.com/jquery/ajax-ajax.html

html(../Home/Index.cshtml)

<body>
    <button class="Btn">按钮</button>
</body>

js

contentType类型:"application/json; charset=utf-8","text/xml","application/x-www-form-urlencoded","application/x-javascript; charset=utf-8"

dataType类型:"json","html","text","script","jsonp","xml"

$(document).ready(function () {
    $(".Btn").click(function () {
        $.ajax({
            type: "POST",
            url: "../Home/Index",
            data: {},
            contentType: "application/x-www-form-urlencoded;charset=UTF-8",
            dataType: "json",
            success: function (data) {
                for(var i = 0;i < data.List.length;i++){
           var obj = data.List[i];
            alert(obj); 
        }
}, error: function (data) { alert("出错了"); } }); }); });

HomeController

public JsonResult Index()
{
  ArrayList list = new ArrayList() {"1","2","3" };
  var m = new { List = list };
  return Json(m ,JsonRequestBehavior.AllowGet);
}