I have a reusable function of jquery Autocomplete in a file function.js. The function has as parameters the url for the ajax call and some additional values taken from the fields of a form
In another file, anag.js, I have several calls to this function.
The problem is that when it is executed, the value of the form fields remain the old one.
For example:
field prov = LI
field city = Livorno
When I change the value of the prov
in MO
, the function call autocomplete continues to have the value if field prov = LI
.
I think it's a problem of binding function but can not figure out where is the error.
Autocomplete function (function.js)
function ajaxAutocomplete(elemId, dMinlength, dUrl, extraData){
$("#" + elemId).autocomplete({
source: function( request, response ) {
$.ajax({
url: dUrl,
dataType: "json",
data: 'term=' + request.term + '&' + extraData,
success: function(data) {
response($.map(data, function(item) {
return { label: item.res };
}));
}
});
},
minLength: dMinlength
});
};
Call to autocomplete function (anag.js)
$(function() {
ajaxAutocomplete('luogo_nascita', 2, getBaseURL() + "/default/city_selector", 'prov=' + $("#prov").val() );
});
Thanks
Copyright Notice:Content Author:「volly86」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/23309105/jquery-autocomplete-the-value-passed-to-the-ajax-call-is-wrong