jQuery AutoComplete on Asp.net
<p>I am new on JQuery and Asp.Net. I want to try autocomplete on JQuery but it didn't work. Can you tell me where am I having problem on this .aspx page? Am I having problem on calling search.php file? Jquery is very hard to read and debug.</p>

<p>My aspx page:</p>

<pre><code>&lt;script type="text/javascript"&gt;
    $(document).ready(function() {
    $("#autocomplete").autocomplete('search.php?cmm=all&amp;', {
        minChars: 1,
        max: 10,
        autoFill: false,
        mustMatch: false,
        matchContains: true,
        selectFirst: false,
        scrollHeight: 220,
        formatItem: function(data, i, total) {

            var r = eval('(' + data + ')');                
            return r.title;

        }

    }).result(function(data, selected) {

        var r = eval('(' + selected + ')');

        $(this).val(r.title);

        // Sunucuya istek gönder
        makeRequest(r.id, 'byId');

    });

        //Code to fetch
        $.ajax({
            type: "POST",
            url: "/Service/WSDataService.asmx/GetStates",
            dataType: "json",
            data: "{}",
            contentType: "application/json; charset=utf-8",
            success: function(data) {
                var datafromServer = data.d.split(":");
                $("[id$='txtautofromDB']").autocomplete({
                    source: datafromServer
                });
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                alert(textStatus);
            }
        });

        function makeRequest(msg, command) {

            $.get('search.php?cmm=' + command + '&amp;q=' + msg, function(data) {

                $('#result').html('');

                if (data == '')
                    $('#result').html('Sonuç yok');

                // Sonuç gösteriliyor
                $('#result').append('Sonuç:&lt;br /&gt;' + data);

            });
        }

        $.ajax({
            type: "POST",
            url: "/Service/WSDataService.asmx/GetStatesWithAbbr",
            dataType: "json",
            data: "{}",
            contentType: "application/json; charset=utf-8",
            success: function(data) {
                $('#project').autocomplete({
                    minLength: 0,
                    source: data.d,
                    focus: function(event, ui) {
                        $('#project').val(ui.item.Name);
                        return false;
                    },
                    select: function(event, ui) {
                        $('#project').val(ui.item.Name);
                        $('#selectedValue').text("Selected value:" + ui.item.Abbreviation);
                        return false;
                    }
                });
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                alert(textStatus);
            }
        });  
        });          

&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;form id="form1" runat="server"&gt;
    &lt;div&gt;
        &lt;div&gt;
        &lt;p&gt;AutoComplete Demo &lt;/p&gt;
        &lt;input id="autocomplete" /&gt;
        &lt;/div&gt;        
    &lt;/div&gt;
    &lt;/form&gt;
&lt;/body&gt;
</code></pre>

<p>My search.php file:</p>

<pre><code>&lt;?php
$r=$_REQUEST;

$dummyData=array(
    '{id:1,title:"title1"}',
    '{id:1,title:"title2"}'
);

if(isset($r['cmm'],$r['q'])){

    $result='';

    if($r['cmm']=='all'){

        $result=$dummyData;
        $result=implode("\n",$result);

    }
    else if($r['cmm']=='byId'){

        $result='special result';

    }

    echo $result;   
}
?&gt;
</code></pre>
