custom autocomplete search

I found my problem.

It was just a problem from my search php script! Without trim( $_REQUEST['term'] ) it will not correctly filter results.

Now like this it works perfectly:

function search_autocomplete(){ 

    $posts = get_posts( array(
            's' => trim( $_REQUEST['term'] ), 'post_type' => array('post', 'portfolio')
        ) );
    $suggestions=array();

    global $post;

    $args = array('post_type' => array('post', 'portfolio'), 'posts_per_page' => 10, 'post_status'  => 'publish');
    $post = get_posts($args);

    foreach ($posts as $post): 
        setup_postdata($post);
        $suggestion = array();
        $suggestion['label'] = esc_html($post->post_title);
        $suggestion['link'] = get_permalink();
        $suggestions[]= $suggestion;
    endforeach;

    $response = $_GET["callback"] . "(" . json_encode($suggestions) . ")";  
    echo $response;  
    exit;
}