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.
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