gpt4 book ai didi

javascript - 模拟 ionic 应用程序时无法使用 http 服务连接到服务器

转载 作者:行者123 更新时间:2023-12-03 06:49:31 26 4
gpt4 key购买 nike

我构建了一个简单的 ionic 应用程序来测试我的 API。但我遇到了问题,因为当我以实时重新加载模式(-l 选项)运行它时,一切正常(ionic run ios -l)。但是当我没有使用实时重新加载(ionic run ios)时,我的应用程序似乎出现了错误。我无法调试我的应用程序出错的地方,因为这需要实时重新加载选项,这样就不会发生错误。

我已经重新安装了好几次白名单插件。我将以下行添加到小部件区域内的 config.xml 中。

<access origin="*"/>
<allow-intent href="*"/>
<allow-navigation href="*"/>

以及我的index.html 中的以下行

<meta http-equiv="Content-Security-Policy" content="default-src *; style-src &apos;self&apos; &apos;unsafe-inline&apos;; script-src &apos;self&apos; &apos;unsafe-inline&apos; &apos;unsafe-eval&apos;">

这是我的 Controller 代码

var url="/api/event/new"

.controller('Test', function($http, $scope) {
$http.get(url).then(function(data) {
$scope.allEvents = {
all : function() {
return data.data;
},
remove: function(Events) {
data.data.splice(data.data.indexOf(Events), 1);
},
get : function(_id) {
for (var x in data.data) {
if(data.data[i]._id == _id) {
return data.data[i];
}
}
return null;
}
};
$scope.isNotConnected = false;
}, function(error) {
$scope.allEvents = {
all : function() {
return [{"title" : "Connection error!"}];
}
}
$scope.isNotConnected = true;
console.log(error);
});
})

这是我的 ionic 信息

Cordova CLI: 6.1.1
Ionic Framework Version: 1.3.1
Ionic CLI Version: 1.7.15
Ionic App Lib Version: 0.7.2
ios-deploy version: 1.8.6
ios-sim version: 5.0.8
OS: Mac OS X El Capitan
Node Version: v5.9.1
Xcode version: Xcode 7.3 Build version 7D175

最佳答案

使用远程调试 - iOS 和 Safari

您可以避免使用实时重新加载并使用 safari 调试来查看出了什么问题。

Safari can be used to debug an Ionic app on a connected iOS device. First, we need to enable Web Inspector on the connected device. Web Inspector can be found under Settings > Safari > Advanced. Next, head over to the Safari on your Mac and enable Show Develop menu in menu bar under Safari > Preferences > Advanced. The connected device should now appear in the Develop menu. From there, you can inspect it and use Safari's developer tools to debug your application!

来源:http://ionicframework.com/docs/cli/run.html

关于javascript - 模拟 ionic 应用程序时无法使用 http 服务连接到服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37572957/

26 4 0
文章推荐: javascript -