Search code examples
jqueryjquery-mobilejsonp

jquery mobile auto complete - Null passed to action


Has anyone got auto complete to work? the sample code of jquery (URL adapted) My Action is called, however no value (null) is passed to the action??? Please HELP (http://jquerymobile.com/demos/1.3.0-rc.1/docs/demos/widgets/autocomplete/autocomplete-remote.html)

<script>
        $( document ).on( "pageinit", "#myPage", function() {
            $( "#autocomplete" ).on( "listviewbeforefilter", function ( e, data ) {
                var $ul = $( this ),
                    $input = $( data.input ),
                    value = $input.val(),
                    html = "";
                $ul.html( "" );
                if ( value && value.length > 2 ) {
                    $ul.html( "<li><div class='ui-loader'><span class='ui-icon ui-icon-loading'></span></div></li>" );
                    $ul.listview( "refresh" );
                    $.ajax({
                        url:"@Url.Action("ClientSearch","Schedule")",,
                        dataType: "jsonp",
                        data: {
                            q: $input.val()
                        }
                    })
                    .then( function ( response ) {
                        $.each( response, function ( i, val ) {
                            html += "<li>" + val + "</li>";
                        });
                        $ul.html( html );
                        $ul.listview( "refresh" );
                        $ul.trigger( "updatelayout");
                    });
                }
            });
        });
    </script>

Html

<div data-role="page" class="jqm-demos" id="myPage">
<ul id="autocomplete" data-role="listview" data-inset="true" data-filter="true" data-filter-placeholder="Find a city..." data-filter-theme="d"></ul>
</div>

Solution

  • OK, I've found the issue! It should be: data: { term: $input.val()}