Custom Ajax Based Search Form
Usually in Drupal, the ajax callback is business logic free. You should associate your title (ie string) directly in the form, when ajax had run.
I use this :

function contact_contact_search_form($form, &amp;$form_state) {

$string = '';

//Retrive the string value
if (isset($form_state['values'])) { // Does ajax ran ?
   $string = $form_state['values']['string'];
}

$form['string'] = array(
  '#type' =&gt; 'textfield',
  '#title' =&gt; t('Name'),
);

$form['submit'] = array(
  '#type' =&gt; 'submit',
  '#ajax' =&gt; array(
      'callback' =&gt; 'contact_contact_search_ajax',
      'method' =&gt; 'replace',
      'effect' =&gt; 'none',
  ),
  '#value' =&gt; t('Submit'),
);


// Display the result in the form, but should work if the results are outside of your form
$form['table'] = array(
  '#type' =&gt; 'item',
  '#prefix' =&gt; '&lt;div id="search-table"&gt;',
  '#suffix' =&gt; '&lt;/div&gt;',
  '#markup' =&gt; contact_contact_display_searches($string),
);


return $form;
}


function contact_contact_search_ajax(&amp;$form, &amp;$form_state) {


   $commandes[] = ajax_command_replace('#search-table',drupal_render($form['table']));

   return array(
     '#type' =&gt; 'ajax',
     '#commands' =&gt; $commandes,
   );
}


// Create your table
function contact_contact_display_searches($string) {
// The query
  $query = db_select('node', 'n')
      -&gt;fields('n')
      -&gt;condition('n.title', '%' . db_like($string) . '%', 'LIKE');
      -&gt;range(0, 20)
      -&gt;execute()-&gt;fetchAll();

 // Prepare and clean the results
foreach ($results as $result) {
  $rows[$result-&gt;nid] = array(
      'type' =&gt; check_plain($types[$result-&gt;type]-&gt;name),
      'title' =&gt; l(check_plain($result-&gt;title), 'node/' . $result-&gt;nid),
      'email' =&gt; check_plain($result-&gt;field_pers_email_email),
  );
}

// Simple table theming
$out = theme('table', array(
    'header' =&gt; array(t('Type de contenu'), t('Intitulé'), t('email')),
    'rows' =&gt; $rows,
    'empty' =&gt; t('Aucun résultat avec ces critères de recherche')
        )
  );
}
return $out;


}