与此相关:How do I connect an autocomplete to a textbox?
我正在尝试将自动完成(从jquery ui)链接到文本框。我得到了以下信息:
$("#txtTags").autocomplete({
minLength: 0,
source: function(request, response) {
$.ajax({
type: "POST",
url: "GetTags.asmx/GetTags",
dataType: "xml",
contentType: "text/xml; charset=utf-8",
success: function(xml) {
alert("hi");
// Completion logic goes here
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
},
});为什么我既不能从成功函数也不能从错误函数获得alert?我必须使用jsonp,因为我使用的是一个古老的.net 1.1应用程序,当时(2002/2003)还不支持dataType /jsonp。GetTags.asmx是我的web服务方法。当然,当我在文本框中输入时,我不会得到任何错误,也不会得到自动完成选择。
更新:
修复了成功的问题,所以我得到了成功的功能,问题是为什么我的自动完成文本框仍然是空的?在这个问题顶部的第一个链接中,我已经从数据库中获得了自动补全数据,我将其存储为字符串数组,并在我的webmethod中返回它。我必须在jquery中做什么才能获得这些数据?
编辑2
下面是我从chrome /ie运行webservice (.asmx)文件后的xml文件:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<ArrayOfString xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/quikfix.jakah.com/GetTags">
<string>.net</string>
<string>.net-1.1</string>
<string>3g</string>
<string>6283</string>
<string>7641</string>
<string>8-id</string>
<string>80070005</string>
<string>accounts</string>
<string>actions</string>
<string>activation</string>
<string>active-directory</string>
<string>active-directory</string>
<string>ad</string>
<string>addin</string>
<string>adp</string>
<string>adp-tlm-interface</string>
<string>adptlm</string>
<string>adupdater</string>
<string>ajax</string>
</ArrayOfString>发布于 2013-04-12 04:02:37
从xml中创建数组,并将其传递给响应,如下所示-
success: function(xml) {
var data = [];
$(xml).find('string').each(function(){
data.push($(this).text());
});
response(data);
},发布于 2013-04-12 03:34:28
将函数用于source选项时,最终必须将数组传递给响应方法。
source: function(request, response) {
...
response(thearrayofdata);
...
}https://stackoverflow.com/questions/15957113
复制相似问题