get & upload json data from .conf file

185 views Asked by At

file location Ex: http://localhost:8080/config/userlog.conf (file which having json data)

Below function is for read data from above file.

JSON Data in above file: {"datetime": "01/10/2018 16:33:20", "password": "password123", "username":"[email protected]"}

var getConfigData = function(filename) {
  var data = {
    conf: filename,
    what: 'conf'
  };
  return $.ajax({
    url: '/config/userlog.conf',
    data: data,
    global: false
  });
};
var logData = getConfigData('userlog.conf');
console.log(logData); //output getting undefined

Question: how to read data from .conf file type

2

There are 2 answers

1
MThiele On
$.ajax({url: "/config/userlog.conf"}).done(function(data) {console.log(data);});
1
Clément Bareth On

The ajax request is assigned to logData variable.

You should define it earlier in the code and assign it in the "success" field of the request.

var logData;
var getConfigData = function(filename) {
    return $.ajax({
        url: '/config/'+filename,
        success: data => logData = data,
        global: false
    });
};
getConfigData('userlog.conf');
console.log(logData);