Using jQuery post()
I'm calling an ajax action which returns json ({"Success": "true" }
or {"Success": "false"}
). After getting json I'm trying to set the value of a hidden HTML element to the Success
value in the returned object. After setting the hidden element, it's still empty (not undefined) as per Firebug's watch expression. But after making another identical call the value is set properly. What am I doing wrong?
JavaScript
function setValue() {
$.post('/action', { "data": "dummy" }, function (data) {
if (eval(data.Success))
$('#hiddenResult').prop('value', 'true');
else
$('#authResult').prop('value', 'false');
}, "json").fail(function () {
$('#hiddenResult').prop('value', 'false');
});
}
HTML
<input type="hidden" id="hiddenResult" name="hiddenResult" />