views:

129

answers:

2

Hello!

I am learning Qooxdoo framework and I am trying to make it work with a small Django web service. Django webservice just returns JSON data like this:

{ "name": "Football", "description": "The most popular sport." }

Then I use the following code to query that url:

var req = new qx.io.remote.Request(url, "GET", "application/json");
req.toggleCrossDomain();

req.addListener("completed", function(e) {
                 alert(e.getContent());
                    });
req.send();

Unfortunately when I execute the code I get unexpected token error and then request timeouts.

Uncaught SyntaxError: Unexpected token :
Native.js:91013011 qx.io.remote.RequestQueue[246]: Timeout: transport 248
Native.js:91013011 qx.io.remote.RequestQueue[246]: 5036ms > 5000ms
Native.js:91013013 qx.io.remote.Exchange[248]: Timeout: implementation 249

JSLint reports that this is a valid JSON, so I wonder why Qooxdoo doesn't parse it correctly.

A: 

Your request is timing out. Is the URL right? Are there firewall issues connecting to it? Basically, your code is not receiving the JSON you expect, but is instead receiving a timeout error.

David M
Through logs I can see that server is getting the request correctly, so URL is right and request reaches it.
freiksenet
OK. It's timing out giving the response then. Your error is because the error message (which you have actually posted above) is being parsed as JSON, which it isn't.
David M
I've increased timeout to 1000000ms, JavaScript console shows that it first throws that unexpected token error and only then (much later) gets a timeout.
freiksenet
+4  A: 

The problem is probably with this line:

req.toggleCrossDomain();

crossDomain is false by default, so toggleCrossDomain sets it to true. This forces qx.io.remote.Request to use the script transport, which doesn't work like a regular XMLHttpRequest: The request needs to contain an id, while the server's response must use the same id and wrap the actual response in a call to qx.io.remote.transport.Script._requestFinished(). This is explained in greater detail in the documentation for the qx.io.remote package:

http://demo.qooxdoo.org/current/apiviewer/#qx.io.remote

Daniel Wagner
Thanks, I deployed it on same domain and it did the trick.
freiksenet