自动填充文本框错误 [英] Autocomplete Text box error

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

问题描述

我正在尝试创建一个自动填充文本框。



存储过程



I am trying to create an autocomplete textbox.

Stored Procedure

alter proc usp_test_autocomplete --a
     @Distancedetails varchar(50)
as
begin

select top 10 first_name from tbl_user_master where first_name like  @Distancedetails +'%'

end





前端



我复制了jquery js文件。并在我的aspx页面上粘贴3个js文件。





Front end

i copied the jquery js files. and pasted 3 js files on my aspx page.

<script src="../../jQuery/js/jquery-1.9.1.js" type="text/javascript"></script>
<link href="../../jQuery/css/jquery-ui-1.10.3.custom.min.css" rel="stylesheet" type="text/css" />
<script src="../../jQuery/js/jquery-ui-1.10.3.custom.min.js" type="text/javascript"></script>





然后





------------------- -------------------------------------------------- ---



then


------------------------------------------------------------------------

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%HeaderHTML("Approving Km", 2, 0);%>
<%--<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/themes/base/jquery-ui.css"rel="stylesheet"type="text/css"/>
--%>
<link href="../../Utility/Style/TMS.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="../../jQuery/js/jquery-1.9.1.js" type="text/javascript"></script>
<link href="../../jQuery/css/jquery-ui-1.10.3.custom.min.css" rel="stylesheet" type="text/css" />
<script src="../../jQuery/js/jquery-ui-1.10.3.custom.min.js" type="text/javascript"></script>

<script type="text/javascript" language="javascript">

    $(function() {

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

            source: function(request, response) {

                $.ajax({

                    url: "WebService.asmx/GetEntireNameDetails",
                    data: "{ 'Namedetails': '" + request.term + "' }",
                    dataType: "json",
                    type: "POST",
                    contentType: "application/json; charset=utf-8",

                    success: function(data) {
                    response(data.d);


                    },
                    error: function(result) {

                        alert('incorrect result');
                    }


                });


            }



        });
    });



</script>







------------------------------------------------



i创建了一个Web服务。当我创建Web服务 webservice.cs 是在 App_code 。



服务我写的是








------------------------------------------------

i created a web service . When i created web service webservice.cs got created in App_code.

the service i wrote is


[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService
{

    [WebMethod]
    public List<string> GetEntireNameDetails(string Namedetails)
    {
        DataSet ds = null;
        TMSDatabase TMSComponent = null;
      

        List<string> list = new List<string>();

        try
        {
            TMSComponent = TMSDatabase.CreateInstance();

            ds = TMSComponent.ExecuteStoredProc("usp_test_autocomplete", new TMSDbParameter("@Distancedetails", Namedetails));
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                list.Add(ds.Tables[0].Rows[i]["first_name"].ToString());
            }
        }
        catch
        {

        }

        finally
        {
            if (TMSComponent != null)//databaseComponent is not null
            {
                TMSComponent.CloseConnection();
                TMSComponent = null;
            }


        }
        return list;


    }


}





我在浏览器中查看了Web服务并调用了我在xml中得到了正确的结果



但是当我试图运行代码并在文本框中传递一些内容时我没有得到正确的结果。我收到了错误消息:错误的结果



请向我解释我在哪里做错了。



when i viewed the web service in browser and invoked i was getting the correct result in xml

But when i tried to run the code and pass something in the textbox i did not get the correct result. I got the error message : incorrect result

kindly explain me where i am doing wrong.

推荐答案

function (){


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

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


.ajax({

url: WebService.asmx / GetEntireNameDetails
data: {'Namedetails':' + request.term + '}
dataType: json
type: POST
contentType: 应用/ JSON; charset = utf-8

成功:功能(数据){
response(data.d) ;


},
错误:功能(结果){

alert( ' 错误结果');
}


});


}



});
});



< / 脚本 >
.ajax({ url: "WebService.asmx/GetEntireNameDetails", data: "{ 'Namedetails': '" + request.term + "' }", dataType: "json", type: "POST", contentType: "application/json; charset=utf-8", success: function(data) { response(data.d); }, error: function(result) { alert('incorrect result'); } }); } }); }); </script>







------------------------------------------------



i创建了一个Web服务。当我创建Web服务 webservice.cs 是在 App_code 。



服务我写的是








------------------------------------------------

i created a web service . When i created web service webservice.cs got created in App_code.

the service i wrote is


[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService
{

    [WebMethod]
    public List<string> GetEntireNameDetails(string Namedetails)
    {
        DataSet ds = null;
        TMSDatabase TMSComponent = null;
      

        List<string> list = new List<string>();

        try
        {
            TMSComponent = TMSDatabase.CreateInstance();

            ds = TMSComponent.ExecuteStoredProc("usp_test_autocomplete", new TMSDbParameter("@Distancedetails", Namedetails));
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                list.Add(ds.Tables[0].Rows[i]["first_name"].ToString());
            }
        }
        catch
        {

        }

        finally
        {
            if (TMSComponent != null)//databaseComponent is not null
            {
                TMSComponent.CloseConnection();
                TMSComponent = null;
            }


        }
        return list;


    }


}





我在浏览器中查看了Web服务并调用了我在xml中得到了正确的结果



但是当我试图运行代码并在文本框中传递一些内容时我没有得到正确的结果。我收到了错误消息:错误的结果



请向我解释我在哪里做错了。



when i viewed the web service in browser and invoked i was getting the correct result in xml

But when i tried to run the code and pass something in the textbox i did not get the correct result. I got the error message : incorrect result

kindly explain me where i am doing wrong.


这篇关于自动填充文本框错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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