简体   繁体   中英

Tabris.js XMLHttpRequests not accepting responses: readystate 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM