ajax_update function instead of too much duplicated code