How to group rules in jquery

Posted by Daniele on Stack Overflow See other posts from Stack Overflow or by Daniele
Published on 2010-05-25T08:29:57Z Indexed on 2010/05/25 8:41 UTC
Read the original article Hit count: 382

Filed under:
|
|
|

Hi I've got a simple question. I've this code below, i use ajax three times in very similiar ways the only things that change are the data passed and the id of the target. Is there a way to group these instructions in a simple one? Thx D.

$('#fld_email').focusout(function() {
                    var request_email = $(this).val();              
                    $.ajax({type:"GET",
                            url: "autocomplete.asp",
                            data: "fld=firstname&email="+request_email,
                            beforeSend: function(){$('#fld_firstname').addClass('ac_loading');},
                            success: function(msg){$('#fld_firstname').val(msg);$('#fld_firstname').removeClass('ac_loading'); }
                          });   
                    $.ajax({type:"GET",
                            url: "autocomplete.asp",
                            data: "fld=lastname&email="+request_email,
                            beforeSend: function(){$('#fld_lastname').addClass('ac_loading');},
                            success: function(msg){$('#fld_lastname').val(msg);$('#fld_lastname').removeClass('ac_loading');}
                          });   
                    $.ajax({type:"GET",
                           url: "autocomplete.asp",
                           data: "fld=phone&email="+request_email,
                           beforeSend: function(){$('#fld_phone').addClass('ac_loading');},
                           success: function(msg){$('#fld_phone').val(msg);$('#fld_phone').removeClass('ac_loading');}
                          });   
                    }
                    );

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery