jQuery不会出错或成功 [英] jquery doesnt go to error or success
问题描述
与此相关:我如何将自动完成功能连接到文本框?
我正在尝试将自动完成(从jquery ui)链接到文本框. 我有以下内容:
Im trying to link autocomplete (from jquery ui) to a textbox. I've got the following:
$("#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
?我必须使用dataType XML,因为那时(2002/2003年)不支持古老的.net 1.1
应用程序json/jsonp. GetTags.asmx是我的Web服务方法.但是,当我在文本框中键入内容时,我当然不会出现任何错误,也不会得到自动完成选择.
Why do I not get either alert
from the success function or the error function? I have to use the dataType XML because I am on an ancient .net 1.1
application json/jsonp was not supported back then (2002/2003). GetTags.asmx is my web service method. But of course I do not get any errors nor do I get an autocomplete selection when I type in my textbox.
更新:
解决了成功问题,所以我确实使用了成功功能,问题是为什么我的自动完成文本框仍然空白?在此问题顶部的第一个链接中,我已经从数据库中获取自动完成数据,将其存储为字符串数组,并将其返回到webmethod中.我必须在jquery中做什么才能获取此数据?
Fixed the success issue so I do get to the success function, question is how come my autocomplete textbox still comes up empty? In my first link posted at the top of this question I am already getting my autocomplete data from the database, I store it as a string array and I return it in my webmethod. What must I do in jquery to get this data?
这是我从chrome/运行webservice(.asmx)文件后的xml文件,即:
Here is the xml file after I run the webservice (.asmx) file from chrome / ie:
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>
推荐答案
从xml中创建数组,并将其传递给这样的响应-
create array out of your xml and pass it to the response like this -
success: function(xml) {
var data = [];
$(xml).find('string').each(function(){
data.push($(this).text());
});
response(data);
},
这篇关于jQuery不会出错或成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!