views:

65

answers:

2

Using jQuery UI's "XML data parsed once" autocomplete. I've checked the feed and it comes out as valid and I even logged it with error() and I get OK 200 for the status and 4 for the readystate (the XML file can be seen below).

http://www.finalfantasyunion.com/includes/xml/games.xml

My jQuery code is:

<script>
 $(document).ready(function() {
   $.ajax({
dataType: 'xml',
url: '/includes/xml/games.xml',

success: function(xmlResponse) {
 var data = $('game', xmlResponse).map(function() {
  return {
   name: $('name', this).text(),
   parsed: $('parsed', this).text()
  };
 }).get();

 $("#category").autocomplete({
  source: data,
  minLength: 2,

  select: function(event, ui) {
   alert(ui.item.name);
  }
 });
},

error: function(xmlResponse) {
 console.log(xmlResponse);
}
  })
  });
</script>

If it makes any difference, this file the above code is loaded in is done via Ajax (basically, I have a page which has a div, which loads in a PHP, which include the above code at the top). But I doubt that has anything to do with this, since the xmlResponse seems to appear fine, just can't seem to figure out why success: isn't firing.

+1  A: 

Check the Overview section in the plugin documentation:
The local data can be a simple Array of Strings, or it contains Objects for each item in the array, with either a label or value property or both.

Notice, that you need to have either label or value property in your js object to have it displayed. So, try something like this:

return {
    value: $('name', this).text(),
    name: $('name', this).text(),
    parsed: $('parsed', this).text()
};
Nikita Rybak
Alrighty, I'll keep that in mind.
Shawn Collier
Sorry it took a while to respond to this, it did help me figure out part of the issue.
Shawn Collier
A: 

I think I figured out why it wasn't parsing the XML data correctly a few minutes after I posted this. Sorry for the trouble.

Shawn Collier
Oh, I was mislead, I thought you had problem with autocomplete, not xml parsing.
Nikita Rybak