1

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.

Cooper Wolfe
  • 111
  • 1
  • 7
  • Could you print the request headers that are received? – Moritz Jun 15 '17 at 16:07
  • Access-Control-Allow-Origin:*, Connection:keep-alive, Date:(date), X-Powered-By:Express – Cooper Wolfe Jun 15 '17 at 16:58
  • Is it possible that you are hitting a local server and that port is not open to be connected to from the outside? Even if you're using a local network ip (192.168....) you will still need to open a port to connect to that server from a phone or emulator on the same network. – Dested Jun 15 '17 at 18:45
  • Yeah, like I said I am able to connect to this server from a browser on this port – Cooper Wolfe Jun 16 '17 at 11:54
  • Which version of Tabris.js do you use? The framework is approaching the 2.0 release, and if you use nightly, some changes under the hood will require the exact same versions of the native client and the npm module. If you're using the npm module from one day and the client of another, it might lead to those problems. So an update is always the first thing to try. – ralfstx Jun 19 '17 at 08:12
  • "tabris": "^2.0.0-rc2-dev.20170615" – Cooper Wolfe Jun 30 '17 at 19:07

1 Answers1

0

So as it turns out, my code left completely the same, it started working this morning when I came in. For anyone experiencing the same issue, unfortunately I don't have a solid answer for you except that the last thing I did before it started working was updated tabris. Although this did nothing but replace the files I already had since I was up-to-date to begin with. I also tried testing it on another website which seemed to get it past the block it was having before. For me, I used http://ip.jsontest.com

Cooper Wolfe
  • 111
  • 1
  • 7