Re:How I built a Hacker News mobile web app, Part 2
by enoughalready on Monday March 26, 2012 @12:12PM
(#3757323)
JSONP is considered by most to be a hack and a security risk. CORS is extremely easy to implement, as it only requires you to send some headers to the browser.
For example, in a node app I recently wrote, adding CORS was just a matter of adding these lines:
var allowCrossDomain = function(req, res, next) {
aptUtil.log('using cors to allow for cross domain xhr');
res.header('Access-Control-Allow-Origin', '*'); //any domain can submit requests to us.
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'Content-Type');
next();
}; app.use(allowCrossDomain);
I'm not sure if you had a look at it yet but there is a PhoneGap/Cordova plugin called ChildBrowser that may do what you want here. I can help you getting setup with a PhoneGap project for your app if you want!
"Since it's hosted on another domain, the API supports CORS so that HNmobile can do cross-domain XMLHttpRequests."
Why don't you use JSONP?