After referring to the discussion at , I encountered a challenge with my javascript ajax function that retrieves JSON data. My goal is to trigger different js events based on the key-value pairs of the JSON response, but unfortunately, I am facing difficulties accessing the JSON by key directly. As an alternative, I converted the JSON into a JavaScript object and attempted to use conditional statements (IF), only to find that it's not functioning as expected. Despite receiving a successful response in the JSON, I keep encountering error windows. Given my limited experience in JavaScript, I seek guidance and advice on how to resolve this issue.
success: function (data) {
var json = data,
obj = JSON.parse(json);
if (obj.hasOwnProperty('success')) //if data = {"result":"success"}
{
$('div#loginResult').text("Login result: " + obj.result);
$('div#loginResult').addClass("error");
} else // /if data = {"result":"error"}
{
$('form#loginForm').hide();
$('div#loginResult').text("Login result: " + obj.result);
$('div#loginResult').addClass("success");
}
}