在Asp.net中使用jquery自动完成 [英] Auto complete using jquery in Asp.net

查看:78
本文介绍了在Asp.net中使用jquery自动完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的自动完成文本框仅在每个页面加载时获取数据..它不是连续获取。这是我的代码如下。请帮助我





My auto complete textbox is fetching data on each page load alone..It is not fetching continuously.Here is my code below.Please help me


<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
 <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
     <script type="text/javascript">
         $(function () {

             $("#<%=txtProduct.ClientID %>").autocomplete({

                 source: function (request, response) {

                       $.ajax({

                           url: '<%=ResolveUrl("~/Service.asmx/GetProduct") %>',
                           data: "{ 'prefix': '" + request.term + "'}",
                           dataType: "json",
                           type: "POST",
                           dataFilter: function (data) { return data; },
                           contentType: "application/json; charset=utf-8",
                           success: function (data) {

                               response($.map(data.d, function (item) {

                                   return {
                                       label: item.split('-')[0],
                                       val: item.split('-')[1],
                                   }

                               }))

                           },

                           error: function (response) {
                               alert(response.responseText);
                           },
                           failure: function (response) {
                               alert(response.responseText);
                           }
                       });
                   }, minLength: 1,
                   focus: function (e, i) {
                       $("#<%=hfProduct.ClientID %>").val(i.item.val);
                       return false;
                   },
                   select: function (e, i) {
                       $("#<%=hfProduct.ClientID %>").val(i.item.val);

                   }

               });

           });
       </script>













<asp:TextBox    ID="txtProduct" runat="server"

 ></asp:TextBox>

推荐答案

(function(){
(function () {


(#<% = txtProduct.ClientID %> )。autocomplete({

source:function (请求,响应){
("#<%=txtProduct.ClientID %>").autocomplete({ source: function (request, response) {


.ajax({

url:'<% = ResolveUrl( 〜/ Service.asmx / GetProduct %> ',
数据:{'前缀':'+ request.term +'},
dataType:json,
类型: POST,
dataFilter:function(data){返回数据; },
contentType:application / json; charset = utf-8,
成功:函数(数据){

响应(
.ajax({ url: '<%=ResolveUrl("~/Service.asmx/GetProduct") %>', data: "{ 'prefix': '" + request.term + "'}", dataType: "json", type: "POST", dataFilter: function (data) { return data; }, contentType: "application/json; charset=utf-8", success: function (data) { response(


这篇关于在Asp.net中使用jquery自动完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆