Azu Posted February 5, 2007 Share Posted February 5, 2007 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 Quote Link to comment Share on other sites More sharing options...
Azu Posted February 9, 2007 Author Share Posted February 9, 2007 Bump Quote Link to comment Share on other sites More sharing options...
Zeon Posted February 9, 2007 Share Posted February 9, 2007 now that's a long one-line script . You should use the enter key once in a while maybe someone will be able to read it and give you some advice. Quote Link to comment Share on other sites More sharing options...
fenway Posted February 9, 2007 Share Posted February 9, 2007 That too.. but if it's an AJAX-only question, it's in the wrong forum -- please clarify. Quote Link to comment Share on other sites More sharing options...
Azu Posted February 13, 2007 Author Share Posted February 13, 2007 AJAX just means it uses PHP along with JS. It's a problem with the JS though. For some reason it is only working once and after that it goes all buggy and I have to refresh the page to use it again. Quote Link to comment Share on other sites More sharing options...
fenway Posted February 13, 2007 Share Posted February 13, 2007 I'm sure some variable is simply never being reinitialized. Quote Link to comment Share on other sites More sharing options...
Azu Posted March 6, 2007 Author Share Posted March 6, 2007 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); Quote Link to comment Share on other sites More sharing options...
fenway Posted March 7, 2007 Share Posted March 7, 2007 I can't possible read that code. Quote Link to comment Share on other sites More sharing options...
Azu Posted March 10, 2007 Author Share Posted March 10, 2007 Nevermind I fixed it myself. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.