Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58
js文件中动态加载js文件
因加载顺序不同,在加载js文件时,要动态传的变量还未进行初始化,故参数传不进,
方法是利用ajax异步加载
var IsLoadFieOk = false;//是否已完成js文件的加载 var CallServerIP = "192.168.19.157"; LoadJSfile("scrjquery", "http://"+CallServerIP + "/interface/js/jquery-1.3.2.min.js"); LoadJSfile( "scrDailOut", "http://"+CallServerIP + "/interface/2.js"); function LoadJSfile(sID,url) { IsLoadFieOk = false; AjaxPage(sID,url); var i = 0; while (!IsLoadFieOk && i++<2000) {} //保证异步加载的文件能够做到顺序加载 } function AjaxPage(sId, url){ var oXmlHttp = GetHttpRequest() ; oXmlHttp.OnReadyStateChange = function() { if ( oXmlHttp.readyState == 4 ) { if ( oXmlHttp.status == 200 || oXmlHttp.status == 304 ) { IncludeJS( sId, url, oXmlHttp.responseText ); //alert(url); } else { alert( 'XML request error: ' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')' ) ; } } } oXmlHttp.open('GET', url, true); oXmlHttp.send(null); //return "hello"; }
同时若ajax要跨域访问数据,那么将Internet选项-安全- Internet,受信任的站点中的通过域访问数据资源打开。