function ajax(options) {
        var timeout, // current scheduled but not yet executed request
            requestSequence = 0, // sequence used to drop out-of-order responses
            handler = null,
            quietMillis = options.quietMillis || 100;

        return function (query) {
            window.clearTimeout(timeout);
            timeout = window.setTimeout(function () {
                requestSequence += 1; // increment the sequence
                var requestNumber = requestSequence, // this request's sequence number
                    data = options.data, // ajax data function
                    transport = options.transport || $.ajax,
                    traditional = options.traditional || false,
                    type = options.type || 'GET'; // set type of request (GET or POST)

                data = data.call(this, query.term, query.page, query.context);

                if( null !== handler) { handler.abort(); }

                handler = transport.call(null, {
                    url: options.url,
                    dataType: options.dataType,
                    data: data,
                    type: type,
                    traditional: traditional,
                    success: function (data) {
                        if (requestNumber < requestSequence) {
                            return;
                        }
                        // TODO 3.0 - replace query.page with query so users have access to term, page, etc.
                        var results = options.results(data, query.page);
                        query.callback(results);
                    }
                });
            }, quietMillis);
        };
    }
Produces an ajax-based query function

@param options object containing configuration paramters
@param options.transport function that will be used to execute the ajax request. must be compatible with parameters supported by $.ajax
@param options.url url for the data
@param options.data a function(searchTerm, pageNumber, context) that should return an object containing query string parameters for the above url.
@param options.dataType request data type: ajax, jsonp, other datatatypes supported by jQuery's $.ajax function or the transport function if specified
@param options.traditional a boolean flag that should be true if you wish to use the traditional style of param serialization for the ajax request
@param options.quietMillis (optional) milliseconds to wait before making the ajaxRequest, helps debounce the ajax function if invoked too often
@param options.results a function(remoteData, pageNumber) that converts data returned form the remote request to the format expected by Select2.
     The expected format is an object containing the following keys:
     results array of objects that will be used as choices
     more (optional) boolean indicating whether there are more results available
     Example: {results:[{id:1, text:'Red'},{id:2, text:'Blue'}], more:true}