首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Angular-Oboe + NodeJS流错误前的非空格字符

Angular-Oboe + NodeJS流错误前的非空格字符
EN

Stack Overflow用户
提问于 2015-10-18 04:54:13
回答 1查看 268关注 0票数 0

NodeJS服务器:

代码语言:javascript
复制
var exec = require('child_process').exec;

app.get('/ls', function(req, res) {
  exec('ls',
    function (error, stdout, stderr) {
      res.send(stdout);
  });
});

Angular客户端(来自its GitHubPage上的示例的标准实现):

代码语言:javascript
复制
$scope.myData = [];


Oboe({
        url: $scope.baseUrl + ":" + $scope.port + "/ls",
        pattern: '*',
        start: function(stream) {
            // handle to the stream
            $scope.stream = stream;
            $scope.streamStatus = 'started';
        },
        headers: {
            Authorization: 'Basic '  + $rootScope.globals.currentUser['authdata']
        },
        done: function() {
            $scope.streamStatus = 'done';
        }
    }).then(function() {
        // finished loading
    }, function(error) {
      console.log(error);
        // handle errors
    }, function(node) {
        // node received
        console.log(node);
        $scope.myData.push(node);
    });

当我检查请求时,我得到了以下成功的响应:

代码语言:javascript
复制
data
index.js
license
node_modules
npm-debug.log
package.json
readme.md
routes
test.js

但双胞胎似乎不想处理这件事。下面是我在客户端得到的错误:

代码语言:javascript
复制
Object {statusCode: undefined, body: undefined, jsonBody: undefined, thrown: Error: Non-whitespace before {[.
Ln: 1
Col: 1
Chr: d
    at Error (native)
    at c (http://www.samh…}body: undefinedjsonBody: undefinedstatusCode: undefinedthrown: Error: Non-whitespace before {[.
Ln: 1
Col: 1
Chr: d
    at Error (native)
    at c (http://localhost:8080/vendor/oboe/dist/oboe-browser.min.js:1:1633)
    at h (http://localhost:8080/vendor/oboe/dist/oboe-browser.min.js:1:2054)
    at z (http://localhost:8080/vendor/oboe/dist/oboe-browser.min.js:1:1233)
    at a.emit (http://localhost:8080/vendor/oboe/dist/oboe-browser.min.js:1:7560)
    at XMLHttpRequest.j (http://localhost:8080/vendor/oboe/dist/oboe-browser.min.js:1:6314)__proto__: Object

我还尝试了JSON.stringify()-ing标准输出,但没有用。为什么我会得到这个错误?提前感谢!

EN

回答 1

Stack Overflow用户

发布于 2016-04-06 11:42:21

请在响应中发送一个对象

示例:res.status('yourstatuscode').send(passanobjecthere);

代码语言:javascript
复制
res.status(401).send({
message: 'Server error'
})
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33191468

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档