@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<div>
<input type="button" id="bSend" value="Test" />
</div>
<script src="~/Scripts/jquery-2.0.3.js"></script>
<script>
//以application/json ContentType傳送JSON字串到Server端
jQuery.postJson = function (url, data, callback, type) {
if (jQuery.isFunction(data)) {
type = type || callback;
callback = data;
data = undefined;
}
return jQuery.ajax({
url: url,
type: "POST",
dataType: type,
contentType: "application/json",
data: typeof(data) == "string" ? data : JSON.stringify(data),
success: callback
});
};
</script>
<script>
$("#bSend").click(function () {
var players = [{
Id: 1000, Name: "Darkthread",
RegDate: new Date(Date.UTC(2000, 0, 1)),
Score: 32767
}, {
Id: 1024, Name: "Jeffrey",
RegDate: new Date(Date.UTC(2000, 0, 1)),
Score: 9999
}];
$.postJson("@Url.Content("~/home/send")", players, function (res) {
alert(res);
});
});
</script>
</body>
</html>