【问题标题】:jquery mobile auto complete - Null passed to actionjquery mobile auto complete - 传递给操作的空值
【发布时间】:2014-05-08 05:38:53
【问题描述】:

有没有人可以自动完成工作? jquery的示例代码(URL改编) 我的动作被调用,但是没有值(null)被传递给动作???请帮忙 (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>

【问题讨论】:

  • 您确定您的网址返回值吗?您可以单独测试您的服务吗?
  • URL 被调用,但是当 null 传递给它时,它返回一个 null 值,所以问题是 null 最初传递给了 URL
  • 您能否在整个过程中添加 console.log($input.val()) 以跟踪在您的帖子中的数据中传递的值。您输入的值真的为空吗?你可能有错误的选择器?
  • Ok 补充说,像这样,并且可以看到这些点的值: if (value && value.length > 2) { console.log($input.val()); $ul.html("
  • "); $ul.listview("刷新"); console.log($input.val());
  • 我还应该在哪里添加 console.log($input.val());
  • 标签: jquery jquery-mobile jsonp


    【解决方案1】:

    好的,我找到了问题!应该是:data: { term: $input.val()}

    【讨论】:

      猜你喜欢
      相关资源
      最近更新 更多
      热门标签