I am currently developing a Cloud9 plugin, where I need to make a GET request to a remote web server. The following code is what I use to perform the request:
var http = imports.http;
http.request(url, {}, function(err, data, res) {
if(err) {
alert(err);
}
}
When I perform the same GET request in a web browser, valid JSON is returned. However, using this code, I always receive an Error object, which tells me that the number of loaded bytes is 0. What is going wrong?
The answer I received from the c9 community is the following: The reason is an unpermitted cross origin request (the URL points to a java servlet running on the same host inside a jetty server). The solution is therefore to include an Access-Control-Allow-Origin Header in the servlet's Response.