Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. jQuery(document).ready(function($) {
  2.     $("form").submit(function() {
  3.         form = {dados:""};
  4.    
  5.         $("#"+this.id+" :input").each(function() {
  6.             form.dados += this.name+"="+this.value+"&";
  7.         });
  8.        
  9.         form.dados   = form.dados.substr(0,form.dados.length-1);
  10.         form.type    = $(this).attr("method");
  11.         form.action  = $(this).attr("action");
  12.         form.id      = this.id;
  13.        
  14.         if(form.action == "" || form.action == null)
  15.             form.action = window.location.href.match(/((.*?\x3F|.*))/i)[2];
  16.        
  17.         if(form.type == "" || form.type == null)
  18.             form.type = "POST";
  19.        
  20.         //alert([form.dados,form.action,form.type]); //DEBUG
  21.         form.load = false;
  22.        
  23.         $.ajax({
  24.             type:   form.type,
  25.             url:    form.action,
  26.             data:   form.dados,
  27.             beforeSend: function() {
  28.                 if($("#"+form.id+" #floatLoad").val("1")) {
  29.                     $("#"+form.id+" #load").html("processando formulário...");
  30.                     $("#"+form.id+" #load").show('fast');
  31.                 } else {
  32.                     if($("#"+form.id+" #ajaxCarregar").is(":hidden")) {
  33.                         $("#"+form.id+" #ajaxCarregar").show('fast')
  34.                         form.load = true
  35.                     }
  36.                 }
  37.                    
  38.                 $("#"+form.id+" #ajaxCarregar").attr("class","ajaxCarregar");
  39.             },
  40.             success: function(data) {
  41.                 if(data[0] == '\x7B') {
  42.                     eval("r = "+data);
  43.                     switch(r.status) {
  44.                         case 1:
  45.                             if(r.target!==undefined) {
  46.                                 $("#"+r.target).fadeOut('fast');
  47.                                 $("#"+r.target).html(r.html);
  48.                                 $("#"+r.target).fadeIn('fast');
  49.                             }
  50.                            
  51.                             if(r.mensagem!==undefined)
  52.                                 alert(r.mensagem);
  53.                                
  54.                             if(r.redirect!==undefined)
  55.                                 window.location.href = r.redirect;
  56.                                
  57.                             if(r.some!==undefined)
  58.                                 $("#"+form.id).fadeOut('fast');
  59.                                
  60.                             if(r.script !== undefined)
  61.                                 eval(r.script);
  62.                         break;
  63.                         default:
  64.                             f = "Ocorreu algum erro ao enviar o formulário.\n\n";
  65.                             alert(f+r.mensagem);
  66.                             return 1;
  67.                     }
  68.                 } else
  69.                     return 0;
  70.             },
  71.             complete: function() {
  72.                 if(form.load == true) {
  73.                     $("#"+form.id+" #ajaxCarregar").fadeOut('fast');
  74.                     $("#"+form.id+" #load").fadeOut('fast');
  75.                 } else
  76.                     $("#"+form.id+" #ajaxCarregar").attr("class","subs");
  77.             },
  78.             error: function(){alert("[FORMULÁRIO]\n\nOcorreu algum erro ao processar o formulário, tente novamente.")},
  79.             timeout: function(){alert("[FORMULÁRIO]\n\nO servidor demorou muito para responder, tente novamente.")},
  80.         });
  81.        
  82.         return false;
  83.     });
  84.    
  85.     f=1;
  86.     $("form[id*=ajaxForm]").each(function() {
  87.        $(this).attr("id",this.id+f);
  88.        f++;
  89.     });
  90. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement