angularjs - angular $http.get error, unexpected token -


i starting test simple api using code:

$http.get('/api/products?limit=10').then(function (response) {     console.log(response.status); }); 

and error:

syntaxerror: unexpected token { @ object.parse (native) @ fromjson (http://localhost:8000/bower_components/angular/angular.js:1271:14) @ defaulthttpresponsetransform (http://localhost:8000/bower_components/angular/angular.js:9460:16) @ http://localhost:8000/bower_components/angular/angular.js:9551:12 @ foreach (http://localhost:8000/bower_components/angular/angular.js:340:20) @ transformdata (http://localhost:8000/bower_components/angular/angular.js:9550:3) @ transformresponse (http://localhost:8000/bower_components/angular/angular.js:10319:21) @ processqueue (http://localhost:8000/bower_components/angular/angular.js:14792:28) @ http://localhost:8000/bower_components/angular/angular.js:14808:27 @ scope.$eval (http://localhost:8000/bower_components/angular/angular.js:16052:28)

btw, non angular code, works fine:

function httpgetasync(theurl, callback) {     var xmlhttp = new xmlhttprequest();     xmlhttp.onreadystatechange = function() {          if (xmlhttp.readystate == 4 && xmlhttp.status == 200)             callback(xmlhttp.responsetext);     }     xmlhttp.open("get", theurl, true); // true asynchronous      xmlhttp.send(null); }  httpgetasync('/api/products?limit=10', function(response) {     console.log(response); }); 

some code of api:

res.writehead(200, {     'content-type': 'application/x-json-stream' });  // random delay settimeout(function () {     var i;     (i=0; i<limit; i+=1) {         res.write(json.stringify(createrandomitem(i+skip, sort)) + '\n');     }     res.end(); }, 100 + math.floor(math.random() * 3000)); 

i can't figure out what's problem, tried $resource , didn't worked. can see whole code on github, please help.

i solved in client this:

var warehouseresource = $resource('/api/products?limit=10', {}, {         query: {             method: 'get',             isarray: true,             transformresponse: function(data) {                 data = ('[' + data + ']').replace(/}/g, '},').replace(',\n]', ']');                 return angular.fromjson(data);             }         }     }); 

Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -