自动完成射击不 [英] AutoComplete Not firing

查看:113
本文介绍了自动完成射击不的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这一切看起来好下面我提供了3个部分,如果查询的服务工作正常。



  ///<总结> 
///概要描述AutoCompleteService
///< /总结>
[WebService的空间(namespace =HTTP://模式)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(假)]
[System.Web.Script.Services.ScriptService]
公共类AutoCompleteService:BaseWebService
{
///<总结>
///获取或设置帐户发现者服务。
///< /总结>
公共ICheckoutService CheckOutService {搞定;组; }

///<总结>
///找到匹配无论是在前缀文字给出的邮政编码或郊区的所有地址。
///< /总结>
///< PARAM NAME =prefixText方式>的前缀文字< /参数>
///< PARAM NAME =计数>该计数< /参数>
///<退货和GT;阿雷的详细地址< /回报>
[的WebMethod]
公共字符串[] FindAddresses(字符串prefixText,诠释计数)
{
//检查参数
如果(计数== 0)=计数10;
VAR郊区= CheckOutService.FindMatchingForPartialAddress(prefixText);
返回suburbs.Take(计数).ToArray();


}
}



由JavaScript其次

 < SCRIPT LANGUAGE =JavaScript的> 


$(函数(){
$(#邮编)自动完成({
来源:AutoCompleteService.asmx / FindAddresses,
的minLength:1,
选择:函数(事件,UI){
$(本).VAL(ui.item.value);
}
});
});
< / SCRIPT>



其次是文本框

 < ASP:文本框=服务器NAME =邮编ID =邮政编码>< / ASP:文本框> 



响应

 < ArrayOfStringxmlns:XSI =htt​​p://www.w3.org/2001/XMLSchema-instance的xmlns:XSD =htt​​p://www.w3.org/2001/XMLSchema中的xmlns =HTTP ://schemas.forcetechnology.com.au/2009/04/Fulfilment><串> ABBARIVER,WA,6280< /串><串> ABBEY,WA,6280< /串><串> ACTONPARK ,WA,6280< /串>串GT; ADAMSVALE,WA,6375< /串>< / ArrayOfString> 



好吧,我做了如下改变三江源都指着我在正确的方向,也给我提供了一个出发点,也是这给了我的错误信息,这有助于使修改后的如下。

  [ScriptMethod(ResponseFormat = ResponseFormat.Json )
公共字符串[] FindAddresses(字符串prefixText)
{
//检查参数

VAR郊区= CheckOutService.FindMatchingForPartialAddress(prefixText);
返回suburbs.ToArray();


}


$(文件)。就绪(函数(){
$('[ID $ =邮编]' ).live('keyup.autocomplete',函数(){

$(本).autocomplete({
来源:功能(请求,响应){
警报(要求.term);
$阿贾克斯({
网址:'<%= RESOLVEURL(AutoCompleteService.asmx / FindAddresses)%>',
数据:{prefixText: + request.term +'},
数据类型:JSON,
型:POST,
的contentType:应用/ JSON的;字符集= UTF-8,
成功:功能(数据){
响应($地图(data.d,函数(项目){
返回{
标签:item.split( - ) 0],
VAL:item.split(' - ')[1]
}
}))
},
错误:功能(响应){
警报(response.responseText);
},
失败:功能(响应){
警报(response.responseText);
}
});
},
选择:功能(E,I){
},
的minLength:1
});
});
});


解决方案

试试下面的代码。这是为我工作。



  $(文件)。就绪(函数(){
$('[ ID $ = txtLastname]'。)生活('keyup.autocomplete',函数(){

$(本).autocomplete({
来源:功能(请求,响应){
$阿贾克斯({
网址:'<%= RESOLVEURL(〜/资源/ WebService.asmx /姓氏)%GT;',
数据:{'字头: '+ request.term +'},
数据类型:JSON,
型:POST,
的contentType:应用/ JSON的;字符集= UTF-8,
成功:功能(数据){
响应($地图(data.d,函数(项目){
返回{
标签:item.split( - ) [0],
VAL:item.split(' - ')[1]
}
}))
},
错误:功能(响应){
警报(response.responseText);
},
失败:功能(响应){
警报(response.responseText);
}
});
},
选择:功能(E,I){
},
的minLength:1
});
});



Web方法是



  [的WebMethod] 
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
公共字符串[]姓氏(字符串前缀)
{
名单<串>客户=新的List<串GT;();
使用(SqlConnection的康恩=新的SqlConnection())
{
字符串的ConnectionString = CCMMUtility.GetCacheForWholeApplication();
conn.ConnectionString = ConnectionString的;使用
(CMD的SqlCommand =新的SqlCommand())
{
cmd.CommandText = +
姓LIKE'%',从向tblUsers那里选择不同的顶部(10)姓氏 + @SearchText +'%'按姓氏秩序;
cmd.Parameters.AddWithValue(@ SEARCHTEXT字头);
cmd.Connection =康恩;
conn.Open();使用
(SDR SqlDataReader的= cmd.ExecuteReader())
{
,而(sdr.Read())
{
customers.Add(的String.Format( {0},SDR [姓氏]));
}
}
conn.Close();
}
返回customers.ToArray();
}
}


It all looks good below I have provided the 3 parts the service works fine if queried.

/// <summary>
/// Summary description for AutoCompleteService
/// </summary>
[WebService(Namespace = "http://schemas")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class AutoCompleteService : BaseWebService
{
    /// <summary>
    /// Gets or sets the account finder service.
    /// </summary>
    public ICheckoutService CheckOutService { get; set; }

    /// <summary>
    /// Finds all addresses matching either the postcode or suburb given in the prefix text.
    /// </summary>
    /// <param name="prefixText">The prefix text.</param>
    /// <param name="count">The count.</param>
    /// <returns>Aray of address details</returns>
    [WebMethod]
    public string[] FindAddresses(string prefixText, int count)
    {
        //Check the parameters
        if (count == 0) count = 10;
        var suburbs = CheckOutService.FindMatchingForPartialAddress(prefixText);
        return suburbs.Take(count).ToArray();


    }
}

Followed by javascript

<script language="javascript">


$(function () {
    $("#postcode").autocomplete({
        source: "AutoCompleteService.asmx/FindAddresses",
        minLength: 1,
        select: function (event, ui) {
            $(this).val(ui.item.value);
        }
    });
});
</script>

Followed by textbox

     <asp:TextBox runat="server" name="postcode" id="postcode" ></asp:TextBox>

Response

 <ArrayOfStringxmlns: xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:    xsd="http://www.w3.org/2001/XMLSchema"xmlns="http://schemas.forcetechnology.com.au/2009/04/Fulfilment"><string>ABBARIVER,WA,6280</string><string>ABBEY,WA,6280</string><string>ACTONPARK,WA,6280</string>string>ADAMSVALE,WA,6375</string></ArrayOfString>

OKay I made the following alterations thankyou all for pointing me in the right direction and also providing me with a starting point, also for this gives me error messages which helps so the revised is below.

         [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public string[] FindAddresses(string prefixText)
    {
        //Check the parameters

        var suburbs = CheckOutService.FindMatchingForPartialAddress(prefixText);
        return suburbs.ToArray();


    }


     $(document).ready(function () {
    $('[ID$=postcode]').live('keyup.autocomplete', function () {

        $(this).autocomplete({
            source: function (request, response) {
                alert(request.term);
                $.ajax({
                    url: '<%=ResolveUrl("AutoCompleteService.asmx/FindAddresses") %>',
                    data: "{ prefixText:'" + request.term + "'}",
                    dataType: "json",
                    type: "POST",
                    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);
                    }
                });
            },
            select: function (e, i) {
            },
            minLength: 1
        });
    });
});

解决方案

try the following code. that is working for me..

  $(document).ready(function () {
        $('[ID$=txtLastname]').live('keyup.autocomplete', function () {

            $(this).autocomplete({
                source: function (request, response) {
                    $.ajax({
                        url: '<%=ResolveUrl("~/Resources/WebService.asmx/LastName") %>',
                        data: "{ 'prefix': '" + request.term + "'}",
                        dataType: "json",
                        type: "POST",
                        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);
                        }
                    });
                },
                select: function (e, i) {
                },
                minLength: 1
            });
        });

Web method is

 [WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string[] LastName(string prefix)
{
    List<string> customers = new List<string>();
    using (SqlConnection conn = new SqlConnection())
    {
        string connectionstring = CCMMUtility.GetCacheForWholeApplication();
        conn.ConnectionString = connectionstring;
        using (SqlCommand cmd = new SqlCommand())
        {
            cmd.CommandText = "select distinct top(10) Lastname from tblusers where  " +
            "Lastname  like '%'+ @SearchText + '%' order by Lastname";
            cmd.Parameters.AddWithValue("@SearchText", prefix);
            cmd.Connection = conn;
            conn.Open();
            using (SqlDataReader sdr = cmd.ExecuteReader())
            {
                while (sdr.Read())
                {
                    customers.Add(string.Format("{0}", sdr["Lastname"]));
                }
            }
            conn.Close();
        }
        return customers.ToArray();
    }
}

这篇关于自动完成射击不的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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