【发布时间】:2016-05-05 10:02:03
【问题描述】:
我的项目后端是用端口号 26309 的 VS 实现的,我正在用 notepad++ 中的 ionic 实现我的前端。
我的问题是控制器无法通过:$http.get("http://localhost:26309/api/User/getAll/")检索数据。
解决方案
我解决了这个问题:
1- 在config.xml中添加权限<allow-navigation href="http://*/*"/>
2-安装cordova-plugin-whitelist ionic plugin add cordova-plugin-whitelist
3-向 chrome 添加 control-allow-origin 扩展:https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi/related?hl=en-US
最后:通过在 Application_start 方法中将此代码添加到我的 Global.asax 中来指定后端控制器返回的数据类型:
config.Formatters.JsonFormatter.SerializerSettings.Formatting =
Newtonsoft.Json.Formatting.Indented;
config.Formatters.Remove(config.Formatters.XmlFormatter);
希望这对某人有所帮助
【问题讨论】:
-
你的控制台输出是什么?