I am writing to a generic list where each item holds two values, I’m writing the variables name and valCount to the list.
I have to posts in my page load and i think this is the reason i only get the value 0 returned.
The value i am having issues with is valCount in the post $.post("Dashboard/UserValuationGet" the val count is declared before that method and set to 0.
Even if i set the code to valCount = 5 in the post method that value is still lost, How could i keep that value? is there a way to use session in jQuery?
$(document).ready(function ()
{
$.post("Dashboard/UsersGet", {}, function (dataSet)
{
var obj = jQuery.parseJSON(dataSet);
var table = obj.Table;
var countUsers = 0;
lis = '';
for (var i = 0, len = table.length; i < len; i++)
{
var array = table[i];
if (array.Active == 1)
{
var name = array.Name;
valCount = 0;
$.post("Dashboard/UserValuationGet", {}, function (dataSet1)
{
var obj1 = jQuery.parseJSON(dataSet1);
var table1 = obj1.Table;
for (var i = 0, len = table1.length; i < len; i++)
{
valCount += 1;
}
});
lis += '<li class="subitem1"><a href="#">' + name + '<span>' + valCount + '</span></a></li>';
countUsers = countUsers + 1;
}
}
$("#UserList").empty().html(lis);
$('#userCount').html(countUsers.toString());
});
});
Archer got that bang on.
If you are insistent on server storage, it would be make server round-trip calls and save variables on session and retrieve when needed. Use $.ajax() to set or get data