wp_query() get_col error

UPDATE, Correct Answer:
The core WordPress functions are inaccessible at time when using AJAX calls. The proper way to handle this is covered in “AJAX in Plugins” on the Codex.


Original answer that didn’t solve the issue but might be interesting for others some day.

Here’s an alternate way that avoids having to directly query the DB. You’d replace all of your code up to and including the $res = ... line:

// get search term
$search_query = mysql_escape_string($_POST['value']);
// args for get_posts
$my_post_args = array( 's' => $search_query, 'fields' => 'ids' );
// get array of post IDs (see "fields" argument above)
$my_post_ids = get_posts( $my_post_args );
// now WP_Query args
$res_args = array( 'post__in=' . $my_post_ids );
// make sure that the args parameter matches (it doesn't in your code snippet)
$res = new WP_Query( $res_args );
// etc...