【问题标题】:Sencha Touch Post to Node.js ErrorSencha Touch Post 到 Node.js 错误
【发布时间】:2014-01-21 19:07:14
【问题描述】:

我正在尝试从跨域 node.js 获取带有 Sencha Touch 的 json

我的 node.js 代码:

app.get('/login', function (req, res) {
    console.log("Request handler random was called.");
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    res.writeHead(200, {"Content-Type": "application/json"});
    var otherArray = ["item1", "item2"];
    var otherObject = { item1: "item1val", item2: "item2val" };
    var json = JSON.stringify({ 
        anObject: otherObject, 
        anArray: otherArray, 
        another: "item"
    });
    res.end(json);
});

这里的代码可以正常工作:http://still-stream-9036.herokuapp.com/login

但是当我尝试使用煎茶触摸时,我得到了:

(failed)
Invalid HTTP status code 404

【问题讨论】:

    标签: node.js extjs sencha-touch-2 node.js-domains


    【解决方案1】:

    我在这里找到了解决方案:

    // 启用 CORS

    var enableCORS = function(req, res, next) {
    res.header('Access-Control-Allow-Origin', '*');
    res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
    res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-   Length, X-Requested-With');
    
    // intercept OPTIONS method
    if ('OPTIONS' == req.method) {
      res.send(200);
    }
    else {
      next();
    }
    };
    
    
    // enable CORS!
    app.use(enableCORS);
    //--------------
    

    字体: stackoverflow.com/questions/21236954/sencha-touch-post-to-node-js-error

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-17
      • 2011-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多