0

通过 ajax 连接在同一台机器上使用服务器和客户端时,它显示服务器的非活动状态。在使用动态脚本标记时,它不会反映服务器的不活动状态。如何解决?

我们已将这些函数包含在 .js 文件中。

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();
4

0 回答 0