While Firefox did not produce any error while getting the data from the REST server, Chrome did. This helped me to discover that my server needs to user cors (Cross-origin resource sharing). After including cors into nodejs everything works now.
In case someone is interested, here is the new server. Uses Express instead of Restify though.
var express = require('express'), cors = require('cors');
var app = express();
app.use(express.bodyParser());
app.use(cors());
app.use(app.router);
var users = [
{name:'shopper', cart:[
{text:'Many small thigns', price:1.50, quantity:27},
{text:'Nexus 5 red', price:399.0, quantity:1},
{text:'Something special', price:150.0, quantity:2}
]
}];
app.get('/cart/:id', function(req, res) {
var id = req.params.id;
console.log('id = ' + id)
var cart = [];
users.forEach(function(user) {
if(user.name === id) {
console.log('found the user');
return res.json(user.cart);
}
});
res.statusCode = 404;
return res.send('Error 404: User not found');
});
app.post('/cart', function(req, res) {
console.log('POST');
if(!req.body.hasOwnProperty('name') ||
!req.body.hasOwnProperty('cart')) {
res.statusCode = 400;
return res.send('Error 400: Post syntax incorrect.');
}
var newCart = {
name: req.body.name,
cart: req.body.cart
};
users.push(newCart);
console.log(newCart);
res.json(true);
});
app.listen(process.env.PORT || 3000);