html
Once the data was typed inside it will call autosave2
function to save it via .php. If the new value not different then do nothing.
<tr>
<td><input type="text" class="autosave2" name="price1" data-oval="500" value="700" /></td>
<td><input type="text" class="autosave2" name="price2" data-oval="300" value="500" /></td>
<td><input type="text" class="autosave2" name="price3" data-oval="600" value="800" /></td>
</tr>
jquery
The value from input has sent to .php file and return the result updated
if no errors. Over here, I check the response if it's = updated
then addClass is-valid
to the <input>
itself. The problem is it's not update the input as expect. Despite the same code outside .done
is working fine. (If I un-comment the other lines below). console.log(data)
is working just fine as well.
$(".autosave2").on('blur',function(){
var i_name=$(this).attr('name');
var i_val=$(this).val();
var i_oval=$(this).data('oval');
$.post( "settings_price_limit.php",{name:i_name,val:i_val,oval:i_oval,mode:'default'}, function( data ) {
console.log(data);
if(data=="update"){
$(this).closest('td').find('input.autosave2').addClass('is-valid');
}
});
//$(this).closest('td').find('input.autosave2').addClass('is-valid');
});
settings_price_limit.php
echo "updated";