Passing value through POST on jQuery UI autocomplete result click
<p>I'm trying to pass the id value of the selected item to the search.php file using POST. It works fine if I use GET but doesn't work if I use POST.</p>

<p>Here is the code I have:</p>

<pre><code>$( function() {
    $( ".search" ).autocomplete({
        source: function( request, response ) {
            $.ajax({
                url: "/_inc/autocomplete.php",
                dataType: "json",
                data: {
                    q: request.term
                },
                success: function( data ) {
                    response( data );
                    console.log(data);
                }
            });
        },
        minLength: 2,
        select: function( event, ui ) {
            //alert('selected: ' + ui.item.name);
            var id = ui.item.id;
            $.post("/search.php", {"id": id});
            $(location).attr('href', '/search.php');
        }
    }).data( "ui-autocomplete" )._renderItem = function( ul, item ) {
        if(item.label == 'No Match Found'){
            return $( "&lt;li&gt;" )
            .data( "item.autocomplete", item )
            .append( item.value )
            .appendTo( ul )
            .css("cursor", "default");
        } else {
            return $( "&lt;li&gt;" )
            .data( "item.autocomplete", item )
            .append( ("&lt;a&gt;" + item.id + " - " + item.name + "&lt;/a&gt;") )
            .appendTo( ul );
        }
    };
});
</code></pre>

<p>The data source is pulled from database and converted to JSON using PHP.</p>