I have a tabris.js app that I needed to connect to a SQL database. In order to do so, I decided the best option would be to create an express REST API and then make XMLHttpRequests to it. When the app makes a request, the API shows that a GET request has been made and even responds with a result. I have tested it in a browser and found that the result is being returned flawlessly. The problem is that the readystate of the XHR never leaves 1 and therefore onload/onreadystatechange is never called. At one point I had this app working so I don't know what happened. I will include some mock API code and the Tabris.js code below.
API:
router.get('/', function(req, res) {
res.json({Mock: 'Code'})
})
Tabris:
const xhr = new XMLHttpRequest()
xhr.onload = function() { /* Not called */ }
xhr.onerror = function() { /* Not called */ }
xhr.onabort = function() { /* Not called */ }
xhr.ontimeout = function() { /* Not called */ }
xhr.onreadystatechange = function() {
switch (xhr.readyState) {
case 1: console.log('opened, not sent'); break // Called
case 2: console.log('sent, awaiting response'); break // Not called, even though the API gets the request
case 3: console.log('response received, downloading'); break // Not called
case 4: console.log('finished'); break // Not called
}
}
xhr.open('GET', 'http://ip.ad.dr.ess:port/', true)
xhr.send()
I should also add that the fetch API is not working for me either, though similarly the request is received by the API.