Alternative to XMLHttpRequest in Scriptable

I tried to use XMLHttpRequest in Scriptable - to do a HTTP GET. XMLHttpRequest doesn’t appear to be there.

Following fails Line 1:

var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
    if (xhr.readyState == XMLHttpRequest.DONE) {
        alert(xhr.responseText);
    }
}
xhr.open('GET', 'http://www.ibm.com', true);
xhr.send(null);

And I get the error message

Error on line 1:29: ReferenceError: Can't find variable: XMLHttpRequest

Am I missing something? Is there an alternative? (I looked in the help but nothing struck me.)

This is part of my project to use services provided by Apache/PHP on a Raspberry Pi - so doing a HTTP GET (or POST etc) from Scriptable would be nice.

I think XMLHttpRequest is built in as part of a browser like the DOM or Windows. I don’t think it is a part of the core JavaScript language.

1 Like

That was my concern. And you’ll see I asked the same question for Drafts - over on their Forum.

So, a Scriptable HTTP Request primitive would be handy. Yes, I know it can be done from Shortcuts but that’s forcing the user into “multi-action”. I consider single-action to accomplish a task a strength of javascript- (or python-) based automation.

Well if you could flip it around you can now have your Scriptable script(s) embedded in a Shortcut…

1 Like

Yes, and I’m glad of that. It’s boundary-crossings I’m leery of.

(To be honest, I haven’t yet played with Inline Scripts. To be even more honest, I’m seeking to catalog(ue) ways my Pi server could be invoked from iOS Automation.)

Scriptable already has a Request object

Thanks! I hope you can see why I would’ve missed that. :slight_smile: