I currently have this version of autocomplete control working when returning XML from an .ashx handler. Xml looks like this:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<States>
<State>
<Code>CA</Code>
<Name>California</Name>
</State>
<State>
<Code>NC</Code>
<Name>North Carolina</Name>
</State>
<State>
<Code>SC</Code>
<Name>South Carolina</Name>
</State>
The autocomplete code is as follows:
$('.autocompleteTest').autocomplete(
{
source: function(request, response) {
var list = [];
$.ajax({
url: "http://commonservices.qa.kirkland.com/StateLookup.ashx",
dataType: "xml",
async: false,
data: request,
success: function(xmlResponse) {
list = $("State", xmlResponse).map(function() {
return {
value: $("Code", this).text(),
label: $("Name", this).text()
};
}).get();
}
});
response(list);
},
focus: function(event, ui) {
$('.autocompleteTest').val(ui.item.label);
return false;
},
select: function(event, ui) {
$('.autocompleteTest').val(ui.item.label);
$('.autocompleteValue').val(ui.item.value);
return false;
}
});
For various reasons, I prefer to call the ASP.NET web service, but I cannot get it to work. To go to the service (I'm doing a local service to make it simple), start the autocomplete code:
$('.autocompleteTest').autocomplete(
{
source: function(request, response) {
var list = [];
$.ajax({
url: "/Services/GeneralLookup.asmx/StateList",
dataType: "xml",
This code is located on the page at the root of the site, and GeneralLookup.asmx is located in a subfolder named Services. But the breakpoint in the web service never hits, and no auto-complete list is created. In case it matters, the XML that comes from asmx:
<?xml version="1.0" encoding="utf-8" ?>
<string xmlns="http://www.kirkland.com/"><State> <Code>CA</Code> <Name>California</Name> </State> <State> <Code>NC</Code> <Name>North Carolina</Name> </State> <State> <Code>SC</Code> <Name>South Carolina</Name> </State></string>
, node . jQuery .asmx , .ajax - .ajax, ?
.asmx(~/Services/), , . .
?