This is my code, here I am passing input username and password values. I have written function that input will be checked with json file. If the given input exists "login correct" alert will be displayed else "login incorrect" will be displayed.
but here for me always "login incorrect" is displayed. I do know what wrong in this function. I have tried by using array variable in the function to hold the json file data. then it work correctly. I am having trouble in checking with json file.
help me solve this problem. My input should be checked with json file it exists or not.
<!DOCTYPE html>
<html>
<head>
<script src="jquery.js">
</script>
<script>
$(document).ready(function()
{
var a="user2";
var b="password2";
var checkval = false;
$.getJSON('login.json', function(data)
{
$.each(data,function(i,obj)
{
if(obj.username == a && obj.password == b)
{
checkval = true;
return false;
}
});
});
if(checkval == true)
{
alert("login correct");
}
else
{
alert("!!!!!-----Incorrect login Details-----!!!!!");
}
});
</script>
</head>
<body>
</body>
</html>
and this is my login.json file
[
{
"username": "user1",
"password": "password1"
},
{
"username":"user2",
"password" : "password2"
}
]