Jump to content

[SOLVED] Ajax edit post only working once?


Azu

Recommended Posts

My forum uses Ajax to edit posts but it only works once after that you have to refresh the page for it to work again. Can somebody please tell me how to fix this?

Here is my javascript file;

function datosServidor(){}datosServidor.prototype.iniciar=function(){try{this._xh=new XMLHttpRequest();}catch(e){var _1=new Array("MSXML2.XMLHTTP.5.0","MSXML2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP");var _2=false;for(var i=0;i<_1.length&&!_2;i++){try{this._xh=new ActiveXObject(_1[i]);_2=true;}catch(e){}}if(!_2){return false;}return true;}};datosServidor.prototype.ocupado=function(){estadoActual=this._xh.readyState;return (estadoActual&&(estadoActual<4));};datosServidor.prototype.procesa=function(){if(this._xh.readyState==4&&this._xh.status==200){this.procesado=true;}};datosServidor.prototype.enviar=function(_4,_5){if(!this._xh){this.iniciar();}if(!this.ocupado()){this._xh.open("GET",_4,false);this._xh.send(_5);if(this._xh.readyState==4&&this._xh.status==200){return this._xh.responseText;}}return false;};var urlBase="./";var formVars="";var changing=false;function fieldEnter(_6,_7,_{_7=(_7)?_7:window.event;if(_7.keyCode==13&&_6.value!=""){elem=document.getElementById(_;remotos=new datosServidor;nt=remotos.enviar(urlBase+"?tfn="+escape(elem.id)+"&tfc="+escape(_6.value)+"&"+formVars,"");noLight(elem);elem.innerHTML=nt;changing=false;return false;}else{return true;}}function fieldBlur(_9,_a){if(_9.value!=""){elem=document.getElementById(_a);remotos=new datosServidor;nt=remotos.enviar(urlBase+"?tfn="+escape(elem.id)+"&tfc="+escape(_9.value)+"&"+formVars,"");elem.innerHTML=nt;changing=false;return false;}}function cambia(_b){if(!changing){width=widthEl(_b.id)+20;height=heightEl(_b.id)+2;if(width<100){width=150;}if(height<40){_b.innerHTML="<input id=\""+_b.id+"_field\" style=\"width: "+width+"px;height: "+height+"px;\" maxlength=\"254\" type=\"text\" value=\""+_b.innerHTML+"\" onkeypress=\"return fieldEnter(this,event,'"+_b.id+"')\" onfocus=\"highLight(this);\" onblur=\"noLight(this);return fieldBlur(this,'"+_b.id+"');\" />";}else{_b.innerHTML="<textarea name=\"textarea\" id=\""+_b.id+"_field\" style=\"width: "+width+"px;height: "+height+"px;\" onfocus=\"highLight(this);\" onblur=\"noLight(this);return fieldBlur(this,'"+_b.id+"');\">"+_b.innerHTML+"</textarea>";}changing=true;}_b.firstChild.focus();}function editbox_init(){if(!document.getElementsByTagName){return;}var _c=document.getElementsByTagName("span");for(var i=0;i<_c.length;i++){var _e=_c[i];if(((" "+_e.className+" ").indexOf("HAX")!=-1)&&(_e.id)){_e.onclick=function(){cambia(this);};_e.style.cursor="pointer";_e.title="Edit";}}}function addEvent(_f,_10,fn,_12){if(_f.addEventListener){_f.addEventListener(_10,fn,_12);return true;}else{if(_f.attachEvent){var r=_f.attachEvent("on"+_10,fn);return r;}else{alert("Please upgrade to Mozilla Firefox");}}}function widthEl(_14){if(document.layers){w=document.layers[_14].clip.width;}else{if(document.all&&!document.getElementById){w=document.all[_14].offsetWidth;}else{if(document.getElementById){w=document.getElementById(_14).offsetWidth;}}}return w;}function heightEl(_15){if(document.layers){h=document.layers[_15].clip.height;}else{if(document.all&&!document.getElementById){h=document.all[_15].offsetHeight;}else{if(document.getElementById){h=document.getElementById(_15).offsetHeight;}}}return h;}function highLight(_16){_16.parentNode.style.border="2px solid #D1FDCD";_16.parentNode.style.padding="0";_16.style.border="1px solid #54CE43";}function noLight(_17){_17.parentNode.style.border="0px";_17.parentNode.style.padding="2px";_17.style.border="0px";}function setVarsForm(_18){formVars=_18;}addEvent(window,"load",editbox_init);

 

Oh and the problem occurs in both Firefox and IE7

Link to comment
https://forums.phpfreaks.com/topic/37209-solved-ajax-edit-post-only-working-once/
Share on other sites

  • 3 weeks later...

Okay thanks :) here I added some enters to make it easier to read.

Can you please tell me where I forgot to reinitilize the variable? I can't for the life of me figure out where the problem is =/

 

function datosServidor(){}
datosServidor.prototype.iniciar=function()
{try
{this._xh=new XMLHttpRequest();}
catch(e){
var _1=new Array("MSXML2.XMLHTTP.5.0","MSXML2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP");
var _2=false;
for(var i=0;i<_1.length&&!_2;i++)
{try
{this._xh=new ActiveXObject(_1[i]);_2=true;}catch(e){}}if(!_2){
return false;
}return true;}};
datosServidor.prototype.ocupado=function(){estadoActual=this._xh.readyState;
return (estadoActual&&(estadoActual<4));};
datosServidor.prototype.procesa=function()
{if(this._xh.readyState==4&&this._xh.status==200)
{this.procesado=true;}};
datosServidor.prototype.enviar=function(_4,_5)
{if(!this._xh){this.iniciar();}
if(!this.ocupado())
{this._xh.open("GET",_4,false);
this._xh.send(_5);
if(this._xh.readyState==4&&this._xh.status==200)
{return this._xh.responseText;}}
return false;};
var urlBase="./";
var formVars="";
var changing=false;
function fieldEnter(_6,_7,_
{_7=(_7)?_7:window.event;
if(_7.keyCode==13&&_6.value!=""){elem=document.getElementById(_;
remotos=new datosServidor;
nt=remotos.enviar(urlBase+"?tfn="+escape(elem.id)+"&tfc="+escape(_6.value)+"&"+formVars,"");
noLight(elem);
elem.innerHTML=nt;
changing=false;
return false;}
else{return true;}}
function fieldBlur(_9,_a)
{if(_9.value!="")
{elem=document.getElementById(_a);
remotos=new datosServidor;
nt=remotos.enviar(urlBase+"?tfn="+escape(elem.id)+"&tfc="+escape(_9.value)+"&"+formVars,"");
elem.innerHTML=nt;
changing=false;
return false;}}
function cambia(_b)
{if(!changing)
{width=widthEl(_b.id)+20;
height=heightEl(_b.id)+2;
if(width<100){width=150;}

if(height<40){_b.innerHTML="<input id=\""+_b.id+"_field\" style=\"width: "+width+"px;height: "+height+"px;\" maxlength=\"254\" type=\"text\" value=\""+_b.innerHTML+"\" onkeypress=\"return fieldEnter(this,event,'"+_b.id+"')\" onfocus=\"highLight(this);\" onblur=\"noLight(this);return fieldBlur(this,'"+_b.id+"');\" />";}else{_b.innerHTML="<textarea name=\"textarea\" id=\""+_b.id+"_field\" style=\"width: "+width+"px;height: "+height+"px;\" onfocus=\"highLight(this);\" onblur=\"noLight(this);

return fieldBlur(this,'"+_b.id+"');\">"+_b.innerHTML+"</textarea>";}changing=true;
}_b.firstChild.focus();}
function editbox_init()
{if(!document.getElementsByTagName)
{return;}var _c=document.getElementsByTagName("span");
for(var i=0;i<_c.length;i++){var _e=_c[i];
if(((" "+_e.className+" ").indexOf("HAX")!=-1)&&(_e.id)){_e.onclick=function(){cambia(this);};
_e.style.cursor="pointer";_e.title="Edit";}}}
function addEvent(_f,_10,fn,_12)
{if(_f.addEventListener){_f.addEventListener(_10,fn,_12);
return true;}else{if(_f.attachEvent){var r=_f.attachEvent("on"+_10,fn);
return r;}else{alert("Please upgrade to Mozilla Firefox");}}}
function widthEl(_14){if(document.layers){w=document.layers[_14].clip.width;}
else{if(document.all&&!document.getElementById){w=document.all[_14].offsetWidth;}
else{if(document.getElementById){w=document.getElementById(_14).offsetWidth;}}}
return w;}function heightEl(_15)
{if(document.layers){h=document.layers[_15].clip.height;}else
{if(document.all&&!document.getElementById){h=document.all[_15].offsetHeight;}else
{if(document.getElementById){h=document.getElementById(_15).offsetHeight;}}}
return h;}
function highLight(_16)
{_16.parentNode.style.border="2px solid #D1FDCD";_16.parentNode.style.padding="0";_16.style.border="1px solid #54CE43";}
function noLight(_17)
{_17.parentNode.style.border="0px";_17.parentNode.style.padding="2px";_17.style.border="0px";}function setVarsForm(_18){formVars=_18;}addEvent(window,"load",editbox_init);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.