Jquery Autocomplete: the value passed to the ajax call is wrong
NickName:volly86 Ask DateTime:2014-04-26T17:40:50

Jquery Autocomplete: the value passed to the ajax call is wrong

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

More about “Jquery Autocomplete: the value passed to the ajax call is wrong” related questions

Jquery Autocomplete: the value passed to the ajax call is wrong

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 an...

Show Detail

Retrieve value of Jquery autocomplete into Ajax call

I have a jquery autocomplete field in index.php page : $html .= '<div class="ui-widget"> <label for="tags">Tags:</label> <input id="tags" /&g

Show Detail

Is there a way to call abort() on a jQuery Autocomplete AJAX call?

I'm trying to build a "cancel" link to a jQuery autocomplete field for a large database call. In case it takes too long, it'd be nice if there were a way to cancel the AJAX call that the autocomple...

Show Detail

Jquery .autocomplete not working after ajax call

Hi guys i am trying to write a title matcher, i got it working but when an ajax call is made it no longer works below is my code : <script type="text/javascript" src="jquery.autocomplete.js"&g...

Show Detail

jQuery autocomplete not sending ajax data

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/j

Show Detail

Jquery Autocomplete AJAX call for label value pair JSON data

This is my Jquery Autocomplete code which is not working for dynamic data. I am having json data as label : contact name and value : contact id but this autocomplete doesnt work for AJAX call. $("#

Show Detail

jquery autocomplete with an ajax call to generate the array

i'm trying to do a jquery ui autocomplete with some countries i get from db with an ajax call I'm struggling on how to pass my table of values to the autocomplete $( document ).ready(function() ...

Show Detail

Jquery autocomplete value is not being passed to django form

I am trying to get a textInput from Form where in I am pulling values from Jquery Autocomplete. But the selected value is not being passed to form. What am I missing. $(function() { var

Show Detail

Call Jquery Autocomplete ajax function

I have a Jquery autocomplete ajax function whose source is calculated from code behind. however I am getting the source in javascript using client script manager but my function doesn't execute. ...

Show Detail

JQuery Autocomplete with AJAX

I'm trying to write a JQuery autocomplete script which will call a url via AJAX and update autocomplete results as user enters data into the form. I have my AJAX setup and currently returning JSON...

Show Detail