View
@{
ViewBag.Title = "Index";
}
<script type="text/javascript">
function GetTime() {
$.post("Default1/GetTime/", function (response) {
$("#TimePnl").html(response);
});
return false;
}
function GetUserName(UserName) {
$.get("Default1/GetUserName/?UserName=" + UserName, function (response) {
$("#UserNamePnl").html(response);
});
return false;
}
function GetUserName2(UserName) {
$.get("Default1/GetUserName/", { Action: "post", UserName: UserName }, function (data, textStatus) {
this;
alert(data);
});
return false;
}
</script>
<h2>Index AJAX</h2>
<div id="TimePnl" style="width: 300px; height: 30px; border: 1px dotted silver;">
</div>
<a href="#" onclick="return GetTime();">Click Me</a>
<br />
<div id="UserNamePnl" style="width: 500px; height: 30px; border: 1px dotted silver;">
</div>
<input id="Text1" type="text" onkeyup="return GetUserName(this.value);" />
<br />
<input id="Text2" type="text" onkeyup="return GetUserName2(this.value);" />
Controller
public ActionResult GetTime()
{
return Content("Now Time:"+DateTime.Now.ToString());
}
public ActionResult GetUserName(string UserName)
{
return Content(UserName + "恭喜此用户名可以使用");
}
浙公网安备 33010602011771号