In javascript i am building up a string like this…
var txt = "{authenticationToken: 1, authenticated: 2, authenticationTokenExpiry: 3,sessionTimeoutMinutes: 4,userName: " + userName + "}";
This is later put through and eval statement like this…
var obj = eval('(' + txt + ')');
When this happenings I get a reference error saying the the value of the username variable is undefined.
Does anyone know the reason for this? Is it something simple that I am missing?
Your missing quotes around the username variable:
I assume you want to store the string value of the username in your userName variable. Since it wasn’t quoted it was treating the value of username as a variable. So for example if username was “testValue123” it would of been
userName: testValue123instead ofuserName: 'testValue123'