This is a follow-up to a previous question.
What I need to do is color the cell only after the process successfully updates the record.
$('#example1').on('blur', 'tr > td > .editForecast', function(e)
{
e.preventDefault();
var forecastnewval = $(this).val();
var processData = '';
if(this.value !== $(this).attr('value'))
{
$.post('api/inlineEditProcess.php', {forecastnewval:forecastnewval}, function(data)
{
processData = data; // this is what I'm trying to get now
console.log('this is inside ' + processData); // this prints processData
}
console.log('this is outside ' + processData); // this does not print processData
$(this).css('background-color', '#99FF66'); // this changes the background color of the cell
}
else
{
console.log('nothing changed');
}
});
If you'll notice in the code above, I'm trying to retrieve the variable processData from inside the $.POST and use it in another IF/ELSE statement.
The variable processData will be a string that either reads 'success' or 'fail'. This obviously comes from a PHP process script that runs an UPDATE query, which then returns the words specified.
I want to utilize processData in an IF/ELSE that will change the background color of the cell either to green (for success) or red (for fail).
I simply want to retrieve the variable that was created from within the $.POST.
Can I do this, and if so, how?
processDataoutside the post function, it should work. You are probably going to print undefined right now because you declared the variable inside the function's scope