Javascript 使用服务器活动通知的动态脚本标记
当通过ajax连接在同一台机器上使用服务器和客户端时,它显示服务器的非活动状态。在使用动态脚本标记时,它并不反映服务器的不活动性。如何解决这一问题 我们已经在一个.js文件中包含了这些函数Javascript 使用服务器活动通知的动态脚本标记,javascript,jquery,html,Javascript,Jquery,Html,当通过ajax连接在同一台机器上使用服务器和客户端时,它显示服务器的非活动状态。在使用动态脚本标记时,它并不反映服务器的不活动性。如何解决这一问题 我们已经在一个.js文件中包含了这些函数 function JSONscriptRequest(fullUrl) { this.fullUrl = fullUrl; this.noCacheIE = '&noCacheIE=' + (new Date()).getTime(); this.headLoc = do
function JSONscriptRequest(fullUrl) {
this.fullUrl = fullUrl;
this.noCacheIE = '&noCacheIE=' + (new Date()).getTime();
this.headLoc = document.getElementsByTagName("head").item(0);
this.scriptId = 'JscriptId' + JSONscriptRequest.scriptCounter++;
}
JSONscriptRequest.scriptCounter = 1;
JSONscriptRequest.prototype.buildScriptTag = function () {
this.scriptObj = document.createElement("script");
this.scriptObj.setAttribute("type", "text/javascript");
this.scriptObj.setAttribute("charset", "utf-8");
this.scriptObj.setAttribute("src", this.fullUrl + this.noCacheIE);
this.scriptObj.setAttribute("id", this.scriptId);
}
JSONscriptRequest.prototype.removeScriptTag = function () {
this.headLoc.removeChild(this.scriptObj);
}
JSONscriptRequest.prototype.addScriptTag = function () {
this.headLoc.appendChild(this.scriptObj);
}
并在jsp页面中使用了以下代码
// The web service call
var req = <<<url of the service which resides in different server>>>&callback=<callback function>;
// Create a new request object
bObj = new JSONscriptRequest(req);
// Build the dynamic script tag
bObj.buildScriptTag();
// Add the script tag to the page
bObj.addScriptTag();
//web服务调用
var-req=&callback=;
//创建一个新的请求对象
bObj=新JSONScript请求(req);
//构建动态脚本标记
bObj.buildScriptTag();
//将脚本标记添加到页面
bObj.addScriptTag();
您有一些代码可以让我们看一下吗?如果您提供一个编码示例,我们会更容易帮助您:)www.jsfiddle.net是一个很好的资源。在您的therms中,“它不反映服务器的不活动”是什么?正如我看到的,对象使用给定的src创建脚本标记