2014-01-20 2 views
0

Я пытаюсь получить JSON с Сенча Touch, от перекрестного домена node.jsСенча сенсорный сообщение для Node.js Ошибка

мой 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 

ответ

0

Я нашел решение здесь:

// Позволяет 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