尽管json成功,jquery autocomplete仍无法正常工作

编程入门 行业动态 更新时间:2024-10-15 10:18:36
本文介绍了尽管json成功,jquery autocomplete仍无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

task1.aspx

task1.aspx

<script type="text/javascript" src="jsfiles/validation.js"></script> <script type="text/javascript" src="jsfiles/SearchScript.js"></script> <link rel="stylesheet" href="windowfiles/dhtmlwindow.css" type="text/css" /> <script language="javascript" type="text/javascript" src="windowfiles/dhtmlwindow.js"></script> <link href="css/jquery-ui.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="jsfiles/jquerymin.js" language="javascript"></script> <script type="text/javascript" src="jsfiles/jquery-ui.min.js" language="javascript"></script> <link href="jquery-ui-1817/development-bundle/demos/demos.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" > $(function () { var cache = {}, lastXhr; $("#Grid_RouteDetailCode_ftxtLocationName").autocomplete({ minLength: 1, source: function (request, response) { var term = request.term; if (term in cache) { response(cache[term]); return; } lastXhr = $.getJSON("GetAutoComplete.aspx?r=" + Math.random() + "&name=" + request.term, request, function (data, status, xhr) { cache[term] = data; if (xhr === lastXhr) { response(data); } }); }, select: function (event, ui) { // document.getElementById("birds").value == ui.item.id; //var a = ui.item.id; document.getElementById("locationroute").value = ui.item.id; // document.getElementById("TextBox1").value = ui.item.id; //alert(ui.item.id); } }); });

GetAutoComplete.aspx.vb (来自以下代码让json成功)

GetAutoComplete.aspx.vb(from the below code am getting json success)

Imports System.Data, System.Data.SqlClient, System.Configuration Partial Class GetAutoComplete Inherits System.Web.UI.Page Dim con As SqlConnection Dim cmd As SqlCommand Dim read As SqlDataReader Dim collected_Names As String = "" Dim sa As String = ConfigurationManager.ConnectionStrings("AVLS_MDT_HMS_TTK_FINALConnectionString").ToString() Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load con = New SqlConnection(sa) con.Open() Dim str_Name As String = Trim(Request.QueryString("name")) Dim query As String = "select distinct(Location_Name),id from TMS_Route_Detail_Table where Location_Name like '" & str_Name & "%'" cmd = New SqlCommand(query, con) read = cmd.ExecuteReader() Dim shar As String = "" collected_Names = "[" Do While read.Read() collected_Names += "{""" & "id"":""" & read(1) & """,""label"":""" & read(0).ToString().ToUpper() & """,""value"":""" & read(1) & """" & "}," Loop read.Close() con.Close() If (collected_Names.Length > 1) Then collected_Names = collected_Names.Remove(collected_Names.Length - 1, 1) End If collected_Names += "]" Response.Write(collected_Names) End Sub End Class

推荐答案

( function (){ var cache = {},lastXhr; (function () { var cache = {}, lastXhr;

( #Grid_RouteDetailCode_ftxtLocationName)。autocomplete({ minLength: 1 , source: function (request,response){ var term = request.term; if (在缓存中){ response(cache [term]) ; return ; } lastXhr = ("#Grid_RouteDetailCode_ftxtLocationName").autocomplete({ minLength: 1, source: function (request, response) { var term = request.term; if (term in cache) { response(cache[term]); return; } lastXhr =

.getJSON( GetAutoComplete.aspx?r = + 数学 .random()+ & name = + request.term,request, function (data,status,xhr){ cache [term] = data; if (xhr === lastXhr){响应(数据); } }); }, select: function (event,ui){ // document.getElementById(birds)。value == ui.item.id; / / var a = ui.item.id; document .getElementById( locationroute)。value = ui.item.id; // document.getElementById(TextBox1)。value = ui.item.id; // alert(ui.item.id); } }); }); .getJSON("GetAutoComplete.aspx?r=" + Math.random() + "&name=" + request.term, request, function (data, status, xhr) { cache[term] = data; if (xhr === lastXhr) { response(data); } }); }, select: function (event, ui) { // document.getElementById("birds").value == ui.item.id; //var a = ui.item.id; document.getElementById("locationroute").value = ui.item.id; // document.getElementById("TextBox1").value = ui.item.id; //alert(ui.item.id); } }); });

GetAutoComplete.aspx.vb (来自以下代码让json成功)

GetAutoComplete.aspx.vb(from the below code am getting json success)

Imports System.Data, System.Data.SqlClient, System.Configuration Partial Class GetAutoComplete Inherits System.Web.UI.Page Dim con As SqlConnection Dim cmd As SqlCommand Dim read As SqlDataReader Dim collected_Names As String = "" Dim sa As String = ConfigurationManager.ConnectionStrings("AVLS_MDT_HMS_TTK_FINALConnectionString").ToString() Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load con = New SqlConnection(sa) con.Open() Dim str_Name As String = Trim(Request.QueryString("name")) Dim query As String = "select distinct(Location_Name),id from TMS_Route_Detail_Table where Location_Name like '" & str_Name & "%'" cmd = New SqlCommand(query, con) read = cmd.ExecuteReader() Dim shar As String = "" collected_Names = "[" Do While read.Read() collected_Names += "{""" & "id"":""" & read(1) & """,""label"":""" & read(0).ToString().ToUpper() & """,""value"":""" & read(1) & """" & "}," Loop read.Close() con.Close() If (collected_Names.Length > 1) Then collected_Names = collected_Names.Remove(collected_Names.Length - 1, 1) End If collected_Names += "]" Response.Write(collected_Names) End Sub End Class

更多推荐

尽管json成功,jquery autocomplete仍无法正常工作

本文发布于:2023-11-07 23:20:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1567704.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:无法正常   工作   json   jquery   autocomplete

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!