jQuery

Enviando dados de um formulário usando jQuery

Posted on Fevereiro 7, 2008. Filed under: jQuery | Tags: |

JQuery é um framework de Javascript na minha opinião não é difícil apreender. Este exemplo é para fazer uma inserção usando ajax porém, usando jQuery. Vamos a um exemplo simples.
exemplo1.js
$(document).ready(function(){
$forms = $(‘form’);
$(‘#cadastro’).hide();
$(‘a’).bind(‘click’, function(){
switch(this.id){
case ‘c’:
$(‘#cadastro’).show();
return false;
break;
}
})
$forms.bind(’submit’, function(){
var $button = $(‘button’,this).attr(‘disabled’,true);
var params = $(this.elements).serialize();
var self = this;
$.ajax({
type: ‘POST’,
url: this.action,
data: params,
beforeSend: function(){
$(‘#loading’).show();
$(‘#loading’).html(“Carregando…”);
},
success: function(txt){
$button.attr(‘disabled’,false);
$(‘#loading’).html(txt);
self.reset();
},
error: function(txt){
$(‘#loading’).html(txt);
}
})
return false;
});
});
CSS
body{
font: 12px tahoma,verdana;
margin:0;padding:0;
}
#loading{
display: none;
text-align: [...]

Read Full Post | Make a Comment ( None so far )

Liked it here?
Why not try sites on the blogroll...