我有一个脚本应该从数据库中检索一些行,并根据文本框中选定的自动完成字符串添加到html表中。该函数返回成功,我可以在调试时看到生成的字符串列表,但是在"响应之后我丢失了轨道($。map(data.d,function(item)"被调用。页面的html代码如下:
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="AutoComplete._Default" %>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.0/themes/base/jquery-ui.css" />
<script language="javascript" type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script language="javascript" type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function () {
$("#<%=txtCountry.ClientID%>").autocomplete({
source: function (request, response) {
var param = { keyword: $('#<%=txtCountry.ClientID%>').val() };
$.ajax({
url: "Default.aspx/GetCountryNames",
data: JSON.stringify(param),
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
dataFilter: function (data) { return data; },
success: function (data) {
response($.map(data.d, function (item) {
return {
value: item
}
}))
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
},
select: function (event, ui) {
if (ui.item) {
GetCustomerDetails(ui.item.value);
}
},
minLength: 1
});
});
function GetCustomerDetails(country) {
$("#tblCustomers tbody tr").remove();
$.ajax({
type: "POST",
url: "Default.aspx/GetCustomers",
data: '{country: "' + country + '" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert(data.d);
response($.map(data.d, function (item) {
alert("bump");
var rows = "<tr>"
+ "<td class='customertd'>" + ui.item.value + "</td>"
+ "</tr>";
$('#tblCustomers tbody').append(rows);
}))
},
failure: function (response) {
alert(response.d);
}
});
}
</script>
<div>
Enter Country Name: <asp:TextBox ID="txtCountry" runat="server"></asp:TextBox>
</div>
<br />
<div>
<table id="tblCustomers" class="tblCustomers" >
<thead>
<tr>
<th align="left" class="customerth">CustomerID</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</asp:Content>
总之,自动完成功能工作正常,我选择其中一个结果并调用GetCustomerDetails(country)函数。它从后面的代码调用GetCustomers Web方法,它从数据库中返回我想要的字符串(我在&em后看到了&#34; alert(data.d); &#34; > success:function(data){ row)。但是在&#34; 响应($。map(data.d,function(item)&#34;部分之后)应该有一个警告说&#34; bump&#34;,但没有任何反应。我在这里失踪了什么?
修改
控制台提供&#34;未捕获的ReferenceError:未定义响应&#34;这一行的错误。