AJAX Closures and targeting 'this'
- by Nick Lowman
In the code example below the success callback function logs 'input#04.update' four times rather than each individual input, which makes sense seeing how closures work but how would I go about targeting each individual input using this.
<input type="text" name="" id="01" class="update">
<input type="text" name="" id="02" class="update">
<input type="text" name="" id="03" class="update">
<input type="text" name="" id="04" class="update">
function updateFields(){
$('input.update').each(function(){
$this = $(this);
$.ajax({
data: 'id=' + this.id,
success: function(resp){
console.log($this);
$this.val(resp)
}
});
});
}