Skip to content

Read

Read Method

.read() method can return data either with a Promise or via a provided callback.

[Promise promise = ] .read( [callback] , [options] )

         .read( callback, options )

parameter type description
callback function() Optional callback function where you retrieve your data. If null, a Promise will be returned, which you will need to handle yourself.
options { } Optional object containing additional parameters and overrides

First, include prefs.us Javascript library in your project:

    <script src="https://prefs.us/prefs.us.js"></script>
prefs_us.read( (data) => {
    if (data.success) {
        var mydata = data.values;
    }
});
prefs_us.read()
    .then( (response) => response.json())
    .then((data) => {
        console.log(data.values);
    })
    .catch( (error) => {
        console.log(error);
    });

Note

All data is returned as Content-Type: text/plain