#101485
yavordashew
Member

Hi AUARAGUARD,
If you want to fetch your data from remote server with AJAX request you can do so like this :


window.onload = function () {
    let request = new XMLHttpRequest();
    let url = 'countries.txt';//NOTE THAT IM USING LOCAL FILE
    let data =[]
    request.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
            data = JSON.parse(this.responseText);
        }
    };
    request.open('GET' , url )
    request.send();
    console.log(data)
    const textBox = document.querySelector('smart-text-box');
    textBox.displayMember = 'name';
    textBox.valueMember = 'code';
    textBox.dataSource = function (query, callback) {
        let result = [];
        for (let d = 0; d < data.length; d++) {
            if (data[d].name.toLowerCase().indexOf(query.toLowerCase()) > -1) {
                result.push(data[d]);
            }
        }
        setTimeout(function () {
            callback(result);
        }, 100);
    };
};

Please, do not hesitate to contact us if you have any additional questions.
Best regards,
Yavor Dashev
Smart UI Team
https://www.htmlelements.com/