I have an array that looks like this: {"errors":1, "login_success": false} What I want to do is to separate these two values: 1 and false so that I can do some checks with jquery and so on.
Here's my jquery:
hash = Math.random();
$.ajax({
type: "POST",
url: "java/jquery/AjaxLogin.php",
data: "hash="+hash+"&username="+username+"&password="+password+"&remember_user="+remember_user,
beforeSend : function(){
$("#loading_image").show();
$("body").css("cursor", "wait");
},
error : function(XMLHttpRequest, textStatus, errorThrown){
error = 1;
},
success : function(data) {
$("#loading_image").hide();
$("body").css("cursor", "default");
alert(data);
$.each($.parseJSON(data), function(idx, obj) {
suc = obj.login_success;
er = obj.errors;
alert(er);
});
// data tells whether login ok or not
if(data == -10) {
error = 1;
} else if(data == -1) {
error = 2;
} else if (data > 0) {
// go to homepage
url = "http://intra.tobiasfransman.net/index.php";
$(location).attr('href',url);
}
}
});
But for some reason I can't get two values separated, where are I'm going wrong?