I have this case (a JSON string returned by my server):
{"success": true, "users": [1, 3, 4, 8]}
However, when using this kind of request, I'd get that response as a "string":
var availableUsers = $.ajax({
url: absPath + '/users/findUsers',
type: 'POST',
data: {contents: $('#messageTo').val()},
dataType: 'json',
async: false
}).responseText;
With: alert(typeof(availableUsers));
I'd get: string
return value from typeof
.
When doing this:
window.eval(availableUsers);
It won't be evaluated as expected, to a JavaScript Object.
How can I get the valid JSON response (using, async: false) converted to a JavaScript accessable Object or how can I propertly evaluate the string returned from the server?
Thanks!