Retrieving data from a json file into a variable
Hi guys,
I have these two codes. One give me an array of usernames from a json file. The other one check if a username has been taken (but just from the variable "userList").
How can I implement them together? I want the second code to check inside the json file instead of the variable userList.
Also,is it possible to check inside a mongodb database instead of the json file? I have been looking every where but can't find any recent information about it.
Thank you.
- $.getJSON("/usernames.json", function(data) {
-
- data.forEach(function(item) {
- console.log(item.username);
- });
- });
- /*******************************************************************************/
- var userList = ['admin','vivek','raul','juan'];
-
- function validateUserList() {
- return $.inArray($('#username').val(), userList) > -1
-
- }
-
- $(function() {
- $(':input[name=username]').blur(function() {
-
- if (!validateUserList()) {
-
- $('div#validUser').text('');
- } else {
-
- $('div#validUser').text('Username is already taken.');
- }
-
- });
- });