Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #101481
    AURAGARD
    Member

    Hi Support, looking for an example how to use a ajax request to a remote server?
    Thanks in advance!

    #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/

    #101487
    AURAGARD
    Member

    Thanks Yavor, I expected there is a special “SMART” -ajax-request ? What does the file smart.ajax.js do?
     

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.