how to change jQuery autocomplete plugin default querystring key? (term to that i want)

jQuery autocomplete plugin sent request like this

mysite.com/suggestion?term=Sadegh

is there any way to change term querystring key to another? i can't find option that provide this for me ;)

Answers


I assume you're using jQuery UI AutoComplete

You need to provide a callback as the source, like this:

$(...).autocomplete({
    source: function(term, callback) {
        $.getJSON("url", { foo: term }, callback);
    }
});

The above is not correct for the current release (1.8.6). Not sure if it ever was...

$(...).autocomplete({
  source: function(request, response) {
    $.getJSON("url", { foo: request.term }, response);
  }
});

foo: being the new param key name..


Actually I dug up the code that the plugin uses. Adapting it to change the term would be something like this:

$('#form').autocomplete({
    source: (function() {
        var xhr;
        return function(request, response) {
            if (xhr) {
                xhr.abort();
            }
            xhr = $.ajax({
                url: 'mysite.com/suggestion',
                data: {
                    foo: request.term
                },
                dataType: 'json',
                success: function(data) {
                    response(data);
                },
                error: function() {
                    response([]);
                }
            });
        }
    })()
});

I would say this has 2 advantages:

  1. Abort pending requests
  2. Call the response with an empty set in case of error, which seems more polite to me

Need Your Help

JSON to pandas DataFrame

python json google-maps pandas

What I am trying to do is extract elevation data from a google maps API along a path specified by latitude and longitude coordinates as follows:

Is there a way to import a 3D model into Android?

android 3d opengl-es

Is it possible to create a simple 3D model (for example in 3DS MAX) and then import it to Android?