【发布时间】:2016-11-24 03:33:25
【问题描述】:
我需要知道我能做些什么来解决这个需要修复的问题。我不需要知道问题,需要知道解决方案。有谁知道我该怎么做?
我的离子应用程序:
// controller test:
$http({
method: 'GET',
url: 'https://example.herokuapp.com/apiDataTest/'
}).then(function successCallback(response) {
console.log('response'+response);
}, function errorCallback(response) {
console.log('response'+response);
});
我的api使用快递,是这样的:
var express = require('express');
var app = express();
app.get('/apiDataTest', getData);
function getData(req, res) {
res.json({
message: 'Ok! Welcome to test data!'
});
}
例如,如果我通过浏览器或邮递员调用地址。 json 并根据我的需要返回,但如果你在 AngularJS 中发出请求,由于错误“Access-Control-Allow-Headers”是不可能的。我看到了一些关于它的问题,但没有意识到解决方案本身,有谁知道在哪里(客户端或 api)以及我该如何解决?
【问题讨论】:
-
是的,让你的 api 支持 CORS。这很容易。研究。
标签: angularjs express ionic-framework