I want to set the data that is returned from the success callback in an AJAX request as an input value. This is not working. I have the feeling this is because I am using an AJAX request within an (.on) event function. I need to use the event function within the AJAX request ($this) to find the input I want to update.
$(function () {
$("table").on('change', '.master', function () {
$.ajax({ type: "POST", async: false, url: '<?php echo site_url('wordsuggestion'); ?>/hoi/nederlands/frans', success: function(data) {
$(this).parents('tr').find(".slave").val(data);
}});
});
});
This is the form I'm using.
<tr>
<td>
<div class="form-group"><input type="text" class="master" name="or[0]"></div>
</td>
<td> </td>
<td>
<div class="form-group"><input type="text" class="slave" name="tr[0]"></div>
</td>
</tr>
It is a mystery for me why this is not working. I think that within the AJAX call, the $(this) operator can't be used any more which causes the input not to be updated.