通过jQuery和$.ajax获得值 - 简单DEMO
2017-02-06 15:44:08 访问(3498) 赞(0) 踩(0)
相关下载:Ajax简单示例 源码下载 jquery-1.8.2.min.zip
-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" ValidateRequest="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script language="javascript" type="text/javascript" src="<%=strPhyPath %>/JS/jquery-1.8.2.min.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>通过jQuery和$.ajax获得值</h1>
<a href="Default.aspx">刷新</a><br /><br />
<input type="button" id="btn_OK" value="确定" onclick="AjaxGetValue()" />
<asp:TextBox ID="txt_OutputValue" runat="server" Width="350px"></asp:TextBox>
</div>
</form>
</body>
</html>
<script language="javascript" type="text/javascript">
function AjaxGetValue() {
var ajaxUrl = "<%=strPhyPath %>/Handlers/AjaxHandler.ashx";
$.ajax({
cache: false,
async: true,
url: ajaxUrl,
type: "post",
success: function (data) {
document.getElementById("<%=txt_OutputValue.ClientID%>").value = data;
}
});
}
</script>
-
<%@ WebHandler Language="C#" Class="AjaxHandler" %>
using System;
using System.Web;
public class AjaxHandler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
context.Response.Write("编程帮手:Hello World - " + DateTime.Now.ToString());
}
public bool IsReusable {
get {
return false;
}
}
}
标签:
通过jQuery和$.ajax获得值 - 简单DEMO 


上一条:
下一条:
相关评论
发表评论