views:

23

answers:

2
function one(R) {
  # do some thing..
  $.ajax({
    'url': '/one?search=' + R.val(),
  #some thing common here

}

function two(R) {
  # do some thing..
  $.ajax({
    'url': '/two?search=' + R.val(),
  #some thing common here

}

well, since I'm just doing jQuery, but I guess this can get improve, refactor?

A: 

sure you can,

function one(R, url) {
  # do some thing..
  $.ajax({
    'url': url + R.val(),
  #some thing common here
}

you might tell us why, what you want to do, and give us some morge code (where does the R come from etc). We might be able to give you more information

Nealv
+1  A: 
function search(value, url) {
    $.ajax({url: '/'+url+'?search='+val});
};

search(elem.val(), 'one');

or

$.fn.search = function(url) {
    return this.each(function() {
        $.ajax({url:'/'+url+'?search='+$(this).val()});
    });
}

$('input').search('one');
David