添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
任性的风衣  ·  Your file appears not ...·  1 年前    · 
酒量小的煎饼  ·  Python ...·  1 年前    · 
乐观的针织衫  ·  api调用 java rest ...·  2 年前    · 
How to call System.Configuration.ConfigurationManager.AppSettings["x"] in to javascript file ?
What I have tried:
Tried with config manager and other parameters not succeed. You can't call server-side code directly, you'll need your server code to render a javascript variable that has the data you need and then use that
On your aspx page (or view if you're using MVC)
<script> var mySetting = ' <%=System.Configuration.ConfigurationManager.AppSettings["MySetting"]%>' ; </script> <script src= " /scripts/test.js" ></script>
test.js
$(document).ready(function () { if ( typeof (mySetting) == " undefined" ){ // if you need to check if the variable has been defined you can do this return ; // even though mySetting is defined on your aspx page you can still use it in your js files // as long as they are included after the variable is defined alert(mySetting);
  • Read the question carefully.
  • Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  • If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  • Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question. Let's work to help developers, not make them feel stupid.
  •