Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如何将引导程序typeahead与asp.net asmx一起使用?_Jquery_Asp.net_Twitter Bootstrap_Asmx - Fatal编程技术网

Jquery 如何将引导程序typeahead与asp.net asmx一起使用?

Jquery 如何将引导程序typeahead与asp.net asmx一起使用?,jquery,asp.net,twitter-bootstrap,asmx,Jquery,Asp.net,Twitter Bootstrap,Asmx,在我成功使用asmx将城市列表返回到jQueryUI自动完成插件之前。现在我改用Bootstrap3.0,所以我也改用typeahead 0.9.3,并使用这个插件。 以下是js: $(document).ready(function () { $('#tbDestination').keyup(function (event) { $("input.typeahead").typeahead({ source: function (typeahe

在我成功使用asmx将城市列表返回到jQueryUI自动完成插件之前。现在我改用Bootstrap3.0,所以我也改用typeahead 0.9.3,并使用这个插件。 以下是js:

$(document).ready(function () {
    $('#tbDestination').keyup(function (event) {
        $("input.typeahead").typeahead({
            source: function (typeahead, query) {
                $.get("http://booking.ilvestour.co.th/citysearch.asmx/SearchCity", { text: typeahead },
                function (data) {
                    return query(data.d);
                });
            }
        });
    });
});
以及asmx代码:

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Web.Script.Services
Imports System.Data.SqlClient
<System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class citysearch
    Inherits System.Web.Services.WebService
    <WebMethod()> _
    Public Function SearchCity(ByVal query As String) As List(Of String)
        Dim conn As SqlConnection = New SqlConnection
        conn.ConnectionString = ConfigurationManager.ConnectionStrings("hotelbedsConnectionString").ConnectionString
        Dim cmd As SqlCommand = New SqlCommand
        cmd.CommandText = "SELECT LocalizedDestination.DestinationRusName + '(' + LocalizedDestination.HBDestinationCode + ')' + ', ' + LocalizedCountryName.RusCountryName As Name FROM LocalizedDestination " & _
                          "INNER JOIN LocalizedCountryName On LocalizedDestination.HBCountryCode = LocalizedCountryName.HBCountryCode " & _
                          "WHERE LocalizedDestination.DestinationRusName LIKE '%' + @SearchText + '%'"
        cmd.Parameters.AddWithValue("@SearchText", query)
        cmd.Connection = conn
        conn.Open()
        Dim sdr As SqlDataReader = cmd.ExecuteReader
        Dim CountryNames As New List(Of String)()
        While sdr.Read
            CountryNames.Add(sdr("Name").ToString)
        End While
        conn.Close()
        Return CountryNames
    End Function
End Class


现在我相信web服务肯定有正确的答案。但我还是很困惑。根据文档名称是数据集名称,但这里的数据集名称是什么?

您有一个没有ScriptMethod的ScriptService,传递文本时代码参数名为query,我想知道您是否有正确的http方法post?和http头内容类型:form/x-www-form-urlencoded。Firebug是否显示发出了任何http请求?您的服务器是否使用正确的数据或错误消息进行响应?我敢肯定,服务器使用正确的数据以及http头或与服务器相关的任何其他信息进行响应。但是我混淆了JS部分,真的不知道如何设置这个插件。好吧,看起来像是服务返回xml而不是json。Webservices/methods与soap一起工作,您可能希望在ajax请求中添加ScriptMethod属性和正确的http头。您需要修复参数名称查询与文本。
$(function () {
    $('.typeahead').typeahead({
        name: 'Names',
        remote: {
            url: 'http://booking.ilvestour.co.th/citysearch.asmx/SearchCity?q=%QUERY',
            filter: function (response) {
                return response;
            }
        },
        limit: 10
    });
})
<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
Public Function SearchCity()
    Dim city = HttpContext.Current.Request.QueryString("q")
    Dim conn As SqlConnection = New SqlConnection
    conn.ConnectionString = ConfigurationManager.ConnectionStrings("hotelbedsConnectionString").ConnectionString
    Dim cmd As SqlCommand = New SqlCommand
    cmd.CommandText = "SELECT LocalizedDestination.DestinationRusName + '(' + LocalizedDestination.HBDestinationCode + ')' + ', ' + LocalizedCountryName.RusCountryName As Name FROM LocalizedDestination " & _
                      "INNER JOIN LocalizedCountryName On LocalizedDestination.HBCountryCode = LocalizedCountryName.HBCountryCode " & _
                      "WHERE LocalizedDestination.DestinationRusName LIKE '%' + @SearchText + '%'"
    cmd.Parameters.AddWithValue("@SearchText", city)
    cmd.Connection = conn
    conn.Open()
    Dim sdr As SqlDataReader = cmd.ExecuteReader
    Dim CountryNames As New List(Of String)()
    While sdr.Read
        CountryNames.Add(sdr("Name").ToString)
    End While
    conn.Close()
    Dim s As New JavaScriptSerializer
    Dim json = s.Serialize(CountryNames)
    Return json
End Function