我有一个文本框,当用户键入至少2个字符时,该文本框需要自动完成,但是,它根本无法正常工作。我在另一种形式中具有几乎完全相同的代码,并且工作正常。任何输入将不胜感激!我没有发布C#,因为如您所见,我在console.log列表中确保ajax发布成功(成功)。此外,jquery和jquery-ui脚本在此应用程序的主页中声明。
var shipTo = $('#txtShipTo')
var shipFrom = $('#txtShipFrom')
var addressList = []
$(document).ready(function () {
$.ajax({
type: 'POST',
url: 'Shipping.aspx/fillList',
contentType: 'application/json; charset=utf-8',
success: function (r) {
$.each(r.d, function (index, value) {
addressList.push(value)
})
console.log(addressList)
},
error: function (result) {
alert("Fail")
}
})
})
shipFrom.autocomplete({
minLength: 2,
source: addressList,
})
<%@ Page Title="Shipping Request" Language="C#" MasterPageFile="~/Base.master" AutoEventWireup="true" CodeFile="Shipping.aspx.cs" Inherits="Shipping" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<link href="StyleSheet1.css" rel="stylesheet" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div class="container" id="fromContainer">
<div class="row">
<div class="col-lg-5 col" id="shipFromDiv">
<label for = "txtShipFrom">Shipped From</label>
<asp:TextBox ID="txtShipFrom" runat="server" class="form-control" placeholder="Begin typing..." aria-label=""></asp:TextBox>
<label for = "txtAddress1">Address 1</label>
<asp:TextBox ID="txtAddress1" runat="server" class="form-control" disabled></asp:TextBox>
<label for = "txtAddress2">Address 2</label>
<asp:TextBox ID="txtAddress2" runat="server" class="form-control" disabled></asp:TextBox>
<div class="row">
<div class="col-lg-6 col-5">
<label for = "txtCity">City</label>
<asp:TextBox ID="txtCity" runat="server" class="form-control" disabled></asp:TextBox>
</div>
<div class="col-lg-2 col-3">
<label for = "txtState">State</label>
<asp:TextBox ID="txtState" runat="server" class="form-control" disabled></asp:TextBox>
</div>
<div class="col-lg-4 col-4">
<label for = "txtZip">Zip</label>
<asp:TextBox ID="txtZip" runat="server" class="form-control" disabled></asp:TextBox>
</div>
</div>
<div class="row">
<div class="col-lg-8 col">
<label for = "txtCountry">Country</label>
<asp:TextBox ID="txtCountry" runat="server" class="form-control" disabled></asp:TextBox>
</div>
<div class="col-lg-4 col">
<label for = "txtCode">Code</label>
<asp:TextBox ID="txtCode" runat="server" class="form-control" disabled></asp:TextBox>
</div>
</div>
</div>
<div class="col-lg-6 col" id="shipToDiv">
<label for = "txtShipTo">Shipped To</label>
<asp:TextBox ID="txtShipTo" runat="server" class="form-control" placeholder="Begin typing..."></asp:TextBox>
<label for = "txtAddress3">Address 1</label>
<asp:TextBox ID="txtAddress3" runat="server" class="form-control" disabled></asp:TextBox>
<label for = "txtAddress4">Address 2</label>
<asp:TextBox ID="txtAddress4" runat="server" class="form-control" disabled></asp:TextBox>
<div class="row">
<div class="col-lg-6 col">
<label for = "txtCity">City</label>
<asp:TextBox ID="TextBox1" runat="server" class="form-control" disabled></asp:TextBox>
</div>
<div class="col-lg-2 col">
<label for = "txtState">State</label>
<asp:TextBox ID="TextBox2" runat="server" class="form-control" disabled></asp:TextBox>
</div>
<div class="col-lg-4 col">
<label for = "txtZip">Zip</label>
<asp:TextBox ID="TextBox3" runat="server" class="form-control" disabled></asp:TextBox>
</div>
</div>
<div class="row">
<div class="col-lg-8 col">
<label for = "txtCountry">Country</label>
<asp:TextBox ID="TextBox4" runat="server" class="form-control" disabled></asp:TextBox>
</div>
<div class="col-lg-4 col">
<label for = "txtCode">Code</label>
<asp:TextBox ID="TextBox5" runat="server" class="form-control" disabled></asp:TextBox>
</div>
</div>
</div>
</div>
</div>
<script src="JavaScript2.js"></script>
</asp:Content>