Ver Mensaje Individual
  #1 (permalink)  
Antiguo 15/01/2012, 18:18
codek_orz
 
Fecha de Ingreso: noviembre-2008
Ubicación: el sol
Mensajes: 146
Antigüedad: 15 años, 6 meses
Puntos: 6
Sistema comentarios AJAX (mootools)

Buenas a todos tengo el siguiente codigo
Código Javascript:
Ver original
  1. var MCP = {
  2.     init: function(options){
  3.         this.options = $extend({
  4.             removeForm: true,
  5.             nameError : '<strong>ERROR:</strong> Debe introducir un nombre.',
  6.             emailError : '<strong>ERROR:</strong> Debe introducir una dirección de e-mail válida.',
  7.             msgError : '<strong>ERROR:</strong> Debe escribir un comentario.',
  8.             inmoderation : 'Gracias por el mensaje. En breves momentos será comprobado.'
  9.         }, options || {});
  10.         $('commentform').addEvent('submit', function(ent) {
  11.             this.sendForm(ent);
  12.             return false;
  13.         }.bind(this));
  14.     },
  15.     sendForm : function(ent) {
  16.         try {
  17.             var error = '';
  18.             if($('commentform').author && $('commentform').author.value == '') error = MCP.options.nameError;
  19.             else if($('commentform').email && !(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test($('commentform').email.value))) error = MCP.options.emailError;
  20.             else if($('commentform').comment.value == '' || $('commentform').comment.value == $('commentform').comment.title) error = MCP.options.msgError;
  21.             if(error !='')
  22.                 MCP.errorMsg(error);
  23.             else {
  24.                 $('commentform').addClass('throbbing');
  25.                 $('commentform').send({
  26.                     evalScripts : false,
  27.                     onFailure : function(transport) {
  28.                         try {
  29.                             er = transport.responseText.match(/<p>(.*)<\/p>/);
  30.                             if(er.length) er = er[1];
  31.                             MCP.errorMsg(er);
  32.                             MCP.mcpDone();
  33.                         } catch(e) {
  34.                             MCP.errorMsg("AJAX Error - this may be caused by the browser you're using, or a aserver error- please try again");
  35.                             $('commentform').removeEvents('submit');
  36.                             $('commentform').fireEvent('submit');
  37.                         }
  38.                     },
  39.                     onSuccess : function() {
  40.                         var tr = this.response.text.split(/<body[^>]*?>/);
  41.                             tr = tr[1].split(/<\/body>/);
  42.                         tempDump = new Element('div').setHTML(tr[0]);
  43.                         if($E('.commentlist')){
  44.                             if($E('.commentlist').getChildren().length == $E('.commentlist', tempDump).getChildren().length)
  45.                                 new Element('li').setHTML(MCP.options.inmoderation).addClass('in-moderation').injectInside($E('.commentlist'));
  46.                             else $E('.commentlist', tempDump).getLast().injectInside($E('.commentlist'));
  47.                         }
  48.                         else {
  49.                             if($E('ol',tempDump)) el = $E('ol',tempDump);
  50.                             else el = $E('ul',tempDump);
  51.                             if(!$E("comments",el) && $E('#comments',tempDump)) $E('#comments',tempDump).injectBefore($('commentform'))
  52.                             el.injectBefore($('commentform'));
  53.                         }
  54.                         tempDump.remove();
  55.                         MCP.errorMsg("Gracias por su comentario.");
  56.                         MCP.removeForm();
  57.                         MCP.mcpDone();
  58.                     }
  59.                 });
  60.  
  61.  
  62.  
  63.  
  64.             }
  65.             new Event(ent).stop();
  66.             return false;
  67.         } catch(e) {
  68.             return true;
  69.         }
  70.     },
  71.     removeForm : function() {
  72.         if(MCP.options.removeForm) {
  73.             new Fx.Slide('commentform',{duration:1800,onComplete:function() {$('commentform').remove(); if($('respond')) $('respond').remove()}}).slideOut();
  74.         } else
  75.             $('comment').value = '';
  76.     },
  77.     errorMsg : function(errorMessage) {
  78.         MCP.mcpDone();
  79.         var err = new Element('div', {'class': 'error' }).setHTML(errorMessage).injectBefore($('comment'));
  80.         var errSlide = new Fx.Slide(err);
  81.         var errFx = new Fx.Style(err, 'opacity', {duration:1000});
  82.         errFx.start(0.1,0.9).chain(function(){
  83.             errFx.start(0.9,0.1);
  84.         }).chain(function(){
  85.             errFx.start(0.1,0.9);
  86.         }).chain(function() {
  87.             errSlide.slideOut();
  88.         });
  89.     },
  90.     mcpDone: function () {
  91.         $('comment').removeClass('throbbing');
  92.     }
  93. };
  94. window.addEvent('domready', function() {    if($('commentform')) MCP.init((window.mcpOptions) ? mcpOptions :  {});  });

Se trata de la validación de un formulario para un sistema de comentarios. La cosa es que a la hora de escribir un comentario no recarga la página, quiero forzar que cuando mande el comentario recarge la página... En los errores no, pero cuando se envíe el comentario (en la función onSucces, si no me equivoco) quiero que recarge la página!

Un saludo y gracias