ajax设置入参过大,长轮询Ajax请求被添加每次参数更改

我使用长轮询脚本来检查的在我的数据库更新的记录数

function AjaxRequest(params, url) {

if (params) {

this.params = params;

this.type = "GET";

this.url = url;

// this.contentType = "multipart/form-data";

this.contentLength = params.length;;

}

}

AjaxRequest.prototype.createXmlHttpObject = function() {

try {

this.xmlHttp = new XMLHttpRequest();

}

catch (e) {

try {

this.xmlHttp = new ActiveXObject("Microsoft.XMLHttp");

}

catch (e) {}

}

if (!this.xmlHttp) {

alert("Error creating XMLHttpRequestObject");

}

}

AjaxRequest.prototype.process = function() {

try {

if (this.xmlHttp) {

document.getElementById("loading"+this.params).innerHTML = "loading...";

document.getElementById("loading"+this.params).className = "loading";

this.xmlHttp.onreadystatechange = this.handleRequestStateChange();

this.xmlHttp.open(this.type, this.url, true);

this.xmlHttp.setRequestHeader("Content-Type", this.contentType);

this.xmlHttp.setRequestHeader("Content-Length", this.contentLength);

this.xmlHttp.send(this.params);

}

}

catch (e) {

document.getElementById("loading"+this.params).innerHTML = "";

alert("Unable to connect to server");

}

}

AjaxRequest.prototype.handleRequestStateChange = function() {

var self = this;

return function() {

try {

if (self.xmlHttp.readyState == 4 && self.xmlHttp.status == 200) {

self.handleServerResponse();

}

}

catch (e) {

alert(self.xmlHttp.statusText);

}

};

}

AjaxRequest.prototype.handleServerResponse = function() {

try {

if(this.xmlHttp.responseText.length > 0){

document.getElementById("loading"+this.params).innerHTML = this.xmlHttp.responseText;

}

}

catch (e) {

alert("Error reading server response");

}

}

function CreateAjaxControl(params, url){

var con = $("#"+params+" select").val();

url += "?id="+params+"&con="+con;

var ajaxRequest = new AjaxRequest(params, url);

ajaxRequest.createXmlHttpObject();

ajaxRequest.process();

ajaxRequest.count = 0;

ajaxRequest.progress = CheckingProgress;

ajaxRequest.progress(ajaxRequest, ajaxRequest.params, ajaxRequest.count);

//var ajaxRequest = new AjaxRequest(params, url);

//ajaxRequest.checking = setInterval(function(){CheckingProgress(ajaxRequest.params);}, 100);

}

//function Check(id){

// var res = 0;

// while(res != "done..."){

// res = CheckingProgress(id, res);

// }

//}

function CheckingProgress(obj, id, count){

var self = obj;

if (window.XMLHttpRequest){

xmlhttp8 = new XMLHttpRequest();

}else{

xmlhttp8 = new ActiveXObject("Microsoft.XMLHTTP");

}

xmlhttp8.onreadystatechange = function(){

if (xmlhttp8.readyState==4 && xmlhttp8.status==200){

var result = xmlhttp8.responseText.split(',');

document.getElementById("loading"+id).innerHTML = result[0] + " out of " + result[1];

self.count = result[0];

self.progress(self, self.params, self.count);

}else if(xmlhttp8.status==404){

document.getElementById("loading"+id).innerHTML = "done...";

//return "done";

}

}

xmlhttp8.open("GET","views/test2.php?id="+id+"&count="+count,true);

xmlhttp8.send();

}

,它完美的作品即使世界上没有更新呢,但是当我更新的记录数据库会以新计数作为参数创建新的ajax请求,并且第一个请求仍保持不变。这里似乎是什么问题?这是我把我的长轮询方法附加到一个对象的方式吗?善意帮助。长轮询Ajax请求被添加每次参数更改

+0

函数CreateAjaxControl()是否曾经正在使用?我没有看到它叫任何地方。 –

+0

任何你不使用jQuery的原因?在绝大多数情况下使事情变得更容易。 –

+0

@DanNissenbaum在我的页面中单击按钮时会调用该函数,问题是每当“CheckingProgress()”中的参数发生更改时,将使用新参数创建另一个Ajax请求 –

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值