gpt4 book ai didi

cordova - 应用程序上的 XMLHttpRequest 失败

转载 作者:行者123 更新时间:2023-12-03 15:07:39 24 4
gpt4 key购买 nike

我正在尝试使用 Ionic 框架和 Parse.com 在我的移动应用程序上运行一个简单的 singup 示例。
代码很简单,如下所示:

Parse.initialize(APP_KEY, JS_KEY);
Parse.User.signUp("my.user", "123456", {}, {
success: function(user) {
// Hooray! Let them use the app now.
console.log('yuhuuu ' + user)
},
error: function(user, error) {
// Show the error message somewhere and let the user try again.
alert("Error: " + error.code + " " + error.message);
}
});

这段代码在我的浏览器上测试时有效,但当我在手机上运行时,我收到错误代码 100 并显示以下消息:

enter image description here

我已经尝试改变我唱的方式(使用对象而不是直接传递用户和密码)。还检查了 android 应用程序是否具有访问网络资源的适当权限(没关系)。

最佳答案

深入挖掘后,我发现了这个 link ,这引起了我的注意我的问题的根本原因。 Cordova(Ionic 的底层平台之一)将请求限制为仅本地( file:// )资源,这使得所有外部请求都失败。

为了覆盖此行为,您需要使用 whitelist plugin并将其设置为允许您使用所需的 api 后端。

这可以如下实现。

首先,将插件添加到项目中。

 cordova plugin add https://github.com/apache/cordova-plugin-whitelist.git

然后将您的后端设置到 config.xml 的白名单中文件。
<allow-intent href="*://*api.parse.com/*"/>

关于cordova - 应用程序上的 XMLHttpRequest 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30360244/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com