本文介绍了为什么ASP.NET(3.5)总是加载一个外部的JavaScript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个asp.net 3.5项目中的外部JavaScript。
在编写不同的函数的时候,JavaScript有时被加载到FF中,有时不是(基于FireBug),JavaScript不能运行。
即使JS中有一个错误,它仍然应该加载或浏览器可见,对吧?



加载时的逻辑是什么,什么时候不加载(或者浏览器可以访问)?



$ b

主页从项目中的脚本目录加载JS:

 < head runat =server> 

< asp:ContentPlaceHolder id =headrunat =server>
< / asp:ContentPlaceHolder>
<! - Google JavaScript测量仪 - >
< script src ='http://www.google.com/jsapi'type ='text / javascript'>< / script>
< link href =../ Styles / EliteCircle.css =stylesheettype =text / css/>
< script src =Scripts / JScript.jstype =text / javascript>< / script>
< / head>

JScript.js

  //加载google api 
google.load('visualization','1',{packages:['gauge']});
google.setOnLoadCallback(update);




函数update(x){

var test = parseInt(x.value);

var data = new google.visualization.DataTable();
data.addColumn('string','Label');
data.addColumn('number','Value');
data.addRows(3);
data.setValue(0,0,'Memory');
data.setValue(0,1,0);
data.setValue(1,0,'CPU');
data.setValue(1,1,55);
data.setValue(2,0,'Network');
data.setValue(2,1,68);

var chart = new google.visualization.Gauge(document.getElementById('chart_div'));
var options = {width:400,height:120,redFrom:90,redTo:100,
yellowFrom:75,yellowTo:90,minorTicks:5
};

//平滑过渡到新值,需要实现from值。
setTimeout(function(){data.setValue(0,1,test); chart.draw(data,options);},0);


chart.draw(data,options);




解决方案


I have an external JavaScript in an asp.net 3.5 project.While writing different functions, sometimes the JavaScript is loaded into FF and sometimes it is not (based on FireBug) and the JavaScript does not run.Even if there is an error in the JS it should still load or be visible to the browser, right?

What is the logic behind when it is loaded and when it doesn't load (or is accessible to the browser?)

EDIT

Master Page loads JS from a script directory in project:

<head runat="server">

    <asp:ContentPlaceHolder id="head" runat="server">
    </asp:ContentPlaceHolder>
     <!-- Google JavaScript for gauges -->
       <script src='http://www.google.com/jsapi' type='text/javascript' ></script>   
    <!-- Style Sheet -->
       <link href="../Styles/EliteCircle.css" rel="stylesheet" type="text/css" />    
    <!-- My local JavaScript File -->
       <script src="Scripts/JScript.js" type="text/javascript"></script>    
</head>  

JScript.js

//Load google api
 google.load('visualization', '1', {packages:['gauge']});
 google.setOnLoadCallback(update);




 function update(x) {

 var test = parseInt(x.value);    

 var data = new google.visualization.DataTable();
 data.addColumn('string', 'Label');
 data.addColumn('number', 'Value');
 data.addRows(3);
 data.setValue(0, 0, 'Memory');
 data.setValue(0, 1, 0);
 data.setValue(1, 0, 'CPU');
 data.setValue(1, 1, 55);
 data.setValue(2, 0, 'Network');
 data.setValue(2, 1, 68);

 var chart = new google.visualization.Gauge(document.getElementById('chart_div'));
 var options = { width: 400, height: 120, redFrom: 90, redTo: 100,
 yellowFrom: 75, yellowTo: 90, minorTicks: 5
 };

 //smooth transition to new value, need to implement "from" value.
 setTimeout(function() { data.setValue(0, 1, test); chart.draw(data, options); }, 0);


 chart.draw(data, options);


 }    
解决方案

If it runs, even when it's not loaded, that's most probably because a cached version is used.

这篇关于为什么ASP.NET(3.5)总是加载一个外部的JavaScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 14:02