我想在JavaScript中从web.config的appsettings中检索“imagetype”。我该怎么做?
<script language="JavaScript" type="text/javascript">
var type = '<%= ConfigurationManager.AppSettings["imagetype"] %>';
</script>
var value = System.Configuration.ConfigurationManager.AppSettings["imagetype"];
System.Configuration.dll
的引用,如果你还没有这个引用的话。Response.Clear();
var value = System.Configuration.ConfigurationManager.AppSettings["imagetype"];
Response.Write(value);
Response.End();
现在您可以使用Javascript向页面发起AJAX调用,例如使用ExtJs,并将文本返回到您的javascript中。
或者,您可以将以下内容放入您的页面中:
<script language="javascript" type="text/javascript">
var appSettingValue = '<%=System.Configuration.ConfigurationManager.AppSettings["imagetype"]%>';
// The variable "appSettingValue" will contain the string from your web.config
alert(appSettingValue);
</script>