How to make a synchronous get request in javascript object macros of RiveScript?

369 views Asked by At

I’m new to rivescript i want to make a synchronous ajax get request in javascript object macros of RiveScript. I will be very grateful if anyone can help. Thanks

1

There are 1 answers

0
rodrigoap On BEST ANSWER

This is how you do it. Note that the ajax call is asynchronous.

+ hello
- <call>sendData</call>

> object sendData javascript
    var xhr = new XMLHttpRequest();
    xhr.open('GET', 'myservice/username?id=some-unique-id');
    xhr.onload = function() {
        if (xhr.status === 200) {
            alert('User\'s name is ' + xhr.responseText);
        }
        else {
            alert('Request failed.  Returned status of ' + xhr.status);
        }
    };
    xhr.send();
    return "Done.";
< object