<appSettings>
<add key ="url_house" value="hid"/>
</appSettings>
2.在urlHouse.aspx.cs中:
public string url_house
protected void Page_Load(object sender, EventArgs e)
{
url_house = ConfigurationManager.AppSettings["url_house"]
}
3.在urlHouse.aspx中:
<head runat="server"><title>结果显示</title>
<script language="javascript" src="js/urlHouse.js" type="text/javascript"></script>
<script language="javascript">
function Init_urlHouse()
{
url_house="<%=url_house%>"
}
</script>
</head>
<body onload="Init_urlHouse()">
..........
4.在urlHouse.js中:
alert(urlHouse)
用jquery的ajax就可以的,实例如下:<script src="Jquery/jquery-1.4.2-vsdoc.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#btnOK").click(function() {
$.ajax({
//要用post方式
type: "POST",
//方法所在页面和方法名
url: "AjaxPage.aspx/ABC",
data: "{abc:111}", //带参数的,参数名称abc,参数“111”
//date:"{}",//没有参数的初始化
contentType: "application/jsoncharset=utf-8",
dataType: "json",
success: function(data) {
//返回的数据用data.d获取内容
alert(data.d)
}
})
})
})
</script>
<body>
<form id="form1" runat="server">
<asp:Button ID="btnOK" runat="server" Text="ShowText" />
</form>
</body>
后台:引入using System.Web.Services
[WebMethod]
public static string ABC(string abc) //带参数的方法
{
return abc
}
webconfig下得有如下配置节:
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpModules>
这个在vs2008里是可行的,版本低的话,可能不能直接这么调用