Given the following code, how can I reference the input that has autocomplete bound to it from within the success()
function in the $.ajax
call? Neither $(this)
or $e
work.
$('.parent-input').autocomplete({
source: function(request, response) {
$.ajax({
url: "/chunky/bacon",
dataType: 'json',
data: {
product_id: $('#product-id').val(),
term: request.term
},
success: function(data){
var resultCount = data.length;
// I NEED TO REFERENCE .parent-input HERE
response( data );
}
});
},
minLength: 2,
select: function(event, ui){
addAssociatedProduct(ui.item.id, ui.item.value);
$(this).val('');
return false;
}
});
parent-input
? If not, why not just give it an id ofparent-input
instead, and reference it using the selector function? – Luxembourg