Autocomplete source

Autocomplete source

Hi,

I am struggling with the source option in autocomplete. The source data arrives as XML so I trying to reformat the data into an array of objects on success but the response callback does not work for me. In the code below, the first function for source does the correct server request and the array produced by jQuery.ajax.success is in the correct form AFAIK.
  1.     jQuery("input[name='cod']").autocomplete({
  2.         source: function(req, response) {
  3.                     jQuery.ajax({
  4.                         url: '/cgi-bin/search',
  5.                         data: "type=client_code&code=" + req.term,
  6.                         dataType: "xml",
  7.                         success: function( xmlDoc ) {
  8.                                     console.log(xmlDoc);
  9.                                     var clients = [];
  10.                                     var Codes = xmlDoc.getElementsByTagName("client");
  11.                                     console.log("There are "+Codes.length);
  12.                                     for( i = 0; i < Codes.length; ++i ) {
  13.                                         clients.push( {
  14.                                             label : Codes[i].getAttribute("id"),
  15.                                             value: Codes[i].getAttribute("bus_type")
  16.                                         } );
  17.                                     }
  18.                                     console.log(clients);
  19.                                     return clients;
  20.                                 }
  21.                     }),
  22.                 function(data) {
  23.                     console.log(response.data);
  24.                 }
  25.         },
  26.         minLength: 3,
  27.      });
The clients array looks like this:
  1. [Object { label="ADDACT00", value="ORG"}, Object { label="ADDCEN00", value="ORG"} ]
I thought that this data structure would be passed to the response callback and that would be enough but I can't detect that callback being invoked at all.

Can anyone spot my error?
Thanks in advance.
Dermot.


  1. The XML fragment sample.
  2. ...
    <client id="ADDWES00" bus_type="BOO"> ADDWES00 </client>
    <client id="ADDWES02" bus_type="BOO"> ADDWES02 </client>
    <client id="ADDWES05" bus_type="BOO"> ADDWES05 </client>
    <client id="ADDWOR00" bus_type="ADC"> ADDWOR00 </client>
    </clients>