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)
}
});
});
}
You forgot
varDon’t forget
var. One programmer who forgotvarwent to bed at night and woke up to find his apartment on fire. He addedvarand the fire went out. Another programmer leftvarout completely shortly before leaving on a business trip to Europe. The airplane developed in-flight mechanical problems shortly after takeoff, causing the pilot to initiate emergency landing procedures. From his laptop the programmer quickly addedvarand the plane made it safely to an airport.Don’t forget
var. If you putvarin your code, you’ll meet somebody special today. Try it. It sounds amazing but it really works!