function ajax()
{
var xmlhttp=createXMLHttp();
this.url_str='';//php后台文件
this.div_id='';//加载的图层id
this.str='';//传送的数据
var that=this;
this.sendto=function()
{
xmlhttp.open('POST',this.url_str,true);
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlhttp.send(this.str);
}
this.show=function()
{
xmlhttp.onreadystatechange=function ()
{
if(xmlhttp.readyState==4)
{
document.getElementById(that.div_id).innerHTML=xmlhttp.responseText;
document.getElementById("newDrag").style.display="block";
document.getElementById(that.div_id).style.display='block';
bu_re_change();//调用按钮转化设置 //问题是这段 每次调用ajax的时候都要调用这个函数 他们指这里
reputation_bgcolor();//调用声望颜色条设置 //问题是这段 每次调用ajax的时候都要调用这个函数
scroll_set('reputation');//调用声望滚动条设置 //
}
}
xmlhttp.open('POST',this.url_str,true);
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlhttp.send(this.str);
}
//如果把他们放在这边来 监听不到ajax传回的数据元素 没有任何反应 2位置
}问题上面已经写了 就是不希望每次调用ajax的时候到用到他们 请问增加个原型可以办的到吗 或是别的什么办法 只要该用的时候就用到他们
{
var xmlhttp=createXMLHttp();
this.url_str='';//php后台文件
this.div_id='';//加载的图层id
this.str='';//传送的数据
var that=this;
this.sendto=function()
{
xmlhttp.open('POST',this.url_str,true);
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlhttp.send(this.str);
}
this.show=function()
{
xmlhttp.onreadystatechange=function ()
{
if(xmlhttp.readyState==4)
{
document.getElementById(that.div_id).innerHTML=xmlhttp.responseText;
document.getElementById("newDrag").style.display="block";
document.getElementById(that.div_id).style.display='block';
bu_re_change();//调用按钮转化设置 //问题是这段 每次调用ajax的时候都要调用这个函数 他们指这里
reputation_bgcolor();//调用声望颜色条设置 //问题是这段 每次调用ajax的时候都要调用这个函数
scroll_set('reputation');//调用声望滚动条设置 //
}
}
xmlhttp.open('POST',this.url_str,true);
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlhttp.send(this.str);
}
//如果把他们放在这边来 监听不到ajax传回的数据元素 没有任何反应 2位置
}问题上面已经写了 就是不希望每次调用ajax的时候到用到他们 请问增加个原型可以办的到吗 或是别的什么办法 只要该用的时候就用到他们
function ajax()
{
var xmlhttp=createXMLHttp();
this.url_str='';//php后台文件
this.div_id='';//加载的图层id
this.str='';//传送的数据
var that=this;
this.sendto=function()
{
xmlhttp.open('POST',this.url_str,true);
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlhttp.send(this.str);
}
this.show=function(){}
}
//由于ajax返回的元素需要处理的方式不同,所以建议每次调用ajax的时候自己写一个函数来对其属性赋值,这样好点。
function handle1()
{
xmlhttp.onreadystatechange=function ()
{
if(xmlhttp.readyState==4)
{
document.getElementById(that.div_id).innerHTML=xmlhttp.responseText;
document.getElementById("newDrag").style.display="block";
document.getElementById(that.div_id).style.display='block';
}
}
xmlhttp.open('POST',this.url_str,true);
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlhttp.send(this.str);
}
function handle2()
{
xmlhttp.onreadystatechange=function ()
{
if(xmlhttp.readyState==4)
{
document.getElementById(that.div_id).innerHTML=xmlhttp.responseText;
document.getElementById("newDrag").style.display="block";
document.getElementById(that.div_id).style.display='block';
}
}
xmlhttp.open('POST',this.url_str,true);
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlhttp.send(this.str);
}
//ajax调用
var a=new ajax();
a.sendto();
//设置你所需要处理的方法
//需要那些方法的
a.show=handle1;
//不需要那些方法的
//a.show=handle2;
//调用
a.show();
//这样来做不就满足了。
//方法二.
//利用原型也可以做
//就是将ajax这个类作为原型,然后自己再写个类,来继承这个类,自己定义的类把它的show函数给覆盖掉,这个楼主应该会吧
function subAjax(){
this.show=function (){
//handle some thing
}
}
subAjax.prototype=new ajax();
//这样你就可以来调用了
var a=new subAjax();
a.show();//这样这个方法会覆盖父类的方法,这样的话,你就可以来处理了自己想处理的了。