Pracowałem nad tym i nie mogę się nigdzie dostać. Zasadniczo mam autouzupełniania na kilka wejść według klasy, ale muszę uzyskać specyficzne dane wejściowe id, aby zbudować obiekt, aby opublikować ajax (muszę użyć POST dla tego projektu, nie GET).jQuery autouzupełnianie w klasie, jak uzyskać id
$(".input_autocomplete").autocomplete({
source: function(request, response) {
// here is where I get the hash from local storage,
// reference the id and build the object
// tried this.id, $(this).prop('id'), no luck
$.ajax({
url: '/somepath/filename.htm',
contentType: 'application/json',
dataType: 'json',
type: 'POST',
data: JSON.stringify(obj),
success: function(json) {
return {
label: item.label,
value: item.label
}
},
error: function() {
// error handling
}
}); // ajax
} // source
});
Jestem zupełnie nowy w jQuery, ale czy próbowałeś użyciu attr ("id") zamiast .prop ("id")? O ile wiem, id są atr, a nie rekwizyty ... Ponadto, ponieważ używasz składni kropek, $ (this) powinno być sposobem, aby przejść, ponieważ celujesz w obiekt jQuery. Mam nadzieję, że rozwiązuje problem. – rafaelbiten