javascript读取web.config <appSettings> <add key="DomanName" value="......../Resource/" /> </appSettings>想读到这里面的 VALUE 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 通过ajax读取we.config,再var xmlHttp; function createXMLHttpRequest() { if(window.ActiveXObject) { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } else if(window.XMLHttpRequest) { xmlHttp = new XMLHttpRequest(); } }异步获取数据 当一个xml wen jian ,yong "dom" a! 换个思路,后台用个程序中转一下html页面.<!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 type="text/javascript">var Ajax = function(){};Ajax.prototype = { createHttpRequest : function(){ if(window.ActiveXObject){ var ver = ["Microsoft.XMLHTTP","MSXML.XMLHTTP"]; for(var i=0; i<ver.length; i++){ try{ return new window.ActiveXObject(ver[i]); }catch(e){} } }else{ try{ return new XMLHttpRequest(); }catch(e){} } alert("Failure to create HttpRequest!"); }, get : function(url, async, fnCallBack){ var xmlHttp = this.createHttpRequest(); xmlHttp.open("GET", url, async); xmlHttp.onreadystatechange = function(){ if(xmlHttp.readyState == 4 ){ if(xmlHttp.status == 200){ fnCallBack(xmlHttp.responseText); }else{ fnCallBack(null); } } }; xmlHttp.setRequestHeader("If-Modified-Since","0"); xmlHttp.send(null); }};window.onload = function(){ var ajax = new Ajax(); ajax.get("webConfig.ashx", true, function(data){ alert(data); });};</script></head><body></body></html>后面处理程序 webConfig.ashx<%@ WebHandler Language="C#" Class="webConfig" %>using System;using System.Web;using System.Web.UI;using System.Web.Configuration;using System.Xml;public class webConfig : IHttpHandler { public void ProcessRequest (HttpContext context) { context.Response.ContentType = "text/html"; context.Response.Write(getWebConfig()); } public string getWebConfig(){ string result = "not found!"; string strFileName = HttpContext.Current.Server.MapPath(".") + @"\Web.config"; XmlDocument doc = new XmlDocument(); doc.Load(strFileName); XmlNodeList appSetting = doc.DocumentElement.GetElementsByTagName("appSettings"); if(appSetting.Count > 0){ XmlNodeList add = appSetting[0].ChildNodes; for(int i=0; i<add.Count; i++){ XmlNode el= add.Item(i); if(el.NodeType == XmlNodeType.Element && el.Attributes["key"].Value == "DomanName"){ result = el.Attributes["value"].Value; break; } } } return result; } public bool IsReusable { get { return false; } }} <%@ WebHandler Language="C#" Class="webConfig" %>using System;using System.Web;using System.Web.UI;using System.Web.Configuration;using System.Xml;public class webConfig : IHttpHandler { public void ProcessRequest (HttpContext context) { context.Response.ContentType = "text/html"; context.Response.Write(getWebConfig()); } public string getWebConfig(){ string result = "not found!"; string strFileName = HttpContext.Current.Server.MapPath(".") + @"\Web.config"; XmlDocument doc = new XmlDocument(); doc.Load(strFileName); XmlNodeList appSetting = doc.DocumentElement.GetElementsByTagName("appSettings"); if(appSetting.Count > 0){ XmlNodeList add = appSetting[0].ChildNodes; for(int i=0; i<add.Count; i++){ XmlNode el= add.Item(i); if(el.NodeType == XmlNodeType.Element && el.Attributes["key"].Value == "DomanName"){ result = el.Attributes["value"].Value; break; } } } return result; } public bool IsReusable { get { return false; } }} web.config只有让后台才能读取吧,然后用ajax从后台读取支持8L 只能用后台读取,然后用ajax传回来web.config是不允许通过http这样的路径访问的 建议按照 8 楼 Free_Wind22 的思路进行读取 求一个js的双月日历控件。 <!--...//-->是如何hide from old browsers的?? 如何判断一个div中的img全部加载完毕? 窗口全屏问题 求1个正则表达式 形如 E3.216.7 各位帮帮忙,我不记得它的返回值是怎么弄去了,请哪位告诉我一声 如何获得在按下Del键后要删除的内容? 判断汉字字母数字的正则表达式 错在哪里大家帮看看 请问,在javascript中如何释放内存? 用完梅花雨的日历控件后文本框怎么不响应onChange事件啦? 在线等待:如何获得表单里同名的Node集合! 求一正则表达式。。
var xmlHttp;
function createXMLHttpRequest()
{
if(window.ActiveXObject)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest();
}
}
异步获取数据
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>无标题页</title>
<script type="text/javascript">
var Ajax = function(){};
Ajax.prototype = {
createHttpRequest : function(){
if(window.ActiveXObject){
var ver = ["Microsoft.XMLHTTP","MSXML.XMLHTTP"];
for(var i=0; i<ver.length; i++){
try{
return new window.ActiveXObject(ver[i]);
}catch(e){}
}
}else{
try{
return new XMLHttpRequest();
}catch(e){}
}
alert("Failure to create HttpRequest!");
},
get : function(url, async, fnCallBack){
var xmlHttp = this.createHttpRequest();
xmlHttp.open("GET", url, async); xmlHttp.onreadystatechange = function(){
if(xmlHttp.readyState == 4 ){
if(xmlHttp.status == 200){
fnCallBack(xmlHttp.responseText);
}else{
fnCallBack(null);
}
}
};
xmlHttp.setRequestHeader("If-Modified-Since","0");
xmlHttp.send(null);
}
};window.onload = function(){
var ajax = new Ajax();
ajax.get("webConfig.ashx", true, function(data){
alert(data);
});
};
</script>
</head>
<body></body>
</html>
后面处理程序 webConfig.ashx<%@ WebHandler Language="C#" Class="webConfig" %>using System;
using System.Web;
using System.Web.UI;
using System.Web.Configuration;
using System.Xml;public class webConfig : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/html";
context.Response.Write(getWebConfig());
}
public string getWebConfig(){
string result = "not found!";
string strFileName = HttpContext.Current.Server.MapPath(".") + @"\Web.config";
XmlDocument doc = new XmlDocument();
doc.Load(strFileName); XmlNodeList appSetting = doc.DocumentElement.GetElementsByTagName("appSettings"); if(appSetting.Count > 0){
XmlNodeList add = appSetting[0].ChildNodes;
for(int i=0; i<add.Count; i++){
XmlNode el= add.Item(i);
if(el.NodeType == XmlNodeType.Element && el.Attributes["key"].Value == "DomanName"){
result = el.Attributes["value"].Value;
break;
}
}
}
return result;
}
public bool IsReusable {
get {
return false;
}
}}
<%@ WebHandler Language="C#" Class="webConfig" %>using System;
using System.Web;
using System.Web.UI;
using System.Web.Configuration;
using System.Xml;public class webConfig : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/html";
context.Response.Write(getWebConfig());
}
public string getWebConfig(){
string result = "not found!";
string strFileName = HttpContext.Current.Server.MapPath(".") + @"\Web.config";
XmlDocument doc = new XmlDocument();
doc.Load(strFileName); XmlNodeList appSetting = doc.DocumentElement.GetElementsByTagName("appSettings"); if(appSetting.Count > 0){
XmlNodeList add = appSetting[0].ChildNodes;
for(int i=0; i<add.Count; i++){
XmlNode el= add.Item(i);
if(el.NodeType == XmlNodeType.Element && el.Attributes["key"].Value == "DomanName"){
result = el.Attributes["value"].Value;
break;
}
}
}
return result;
}
public bool IsReusable {
get {
return false;
}
}}
支持8L
web.config是不允许通过http这样的路径访问的