XMLHttpRequest在应用程序上失败 [英] XMLHttpRequest failed on App

查看:183
本文介绍了XMLHttpRequest在应用程序上失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Ionic框架和Parse.com在我的移动应用上运行一个简单的单例。
代码如下:

I'm trying to run a simple singup example on my mobile app using Ionic framework and Parse.com. The code is simple as follows:

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 ,并显示以下消息:

This code works when I test it on my browser, but when I run it on my cellphone I get an error code 100 with the following message:

我已经尝试改变我的方式用户和密码)。

I've tried already to change the way I singup (usin the object instead of passing user and password directly). Also checked if the android app has proper permissions for accessing web resources (it's OK).

推荐答案

在深入挖掘一下之后, ve找到此链接,这使我注意到根本原因我的问题。 Cordova(Ionic的底层平台之一)将请求限制为只有本地( file:// )资源,这使得所有外部请求失败。

After digging a little deeper I've found this link, which brought to my attention the root cause of my problem. Cordova (one of underlying platforms of Ionic) limits requests to only local (file://) resources, which made all external requests fail.

为了覆盖此行为,您需要使用白名单插件并进行设置

In order to overwrite this behaviour you need to use the whitelist plugin and set it up to allow you desired api backend.

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

This can be achieved as follows.

First, add the plugin to the project.

然后将您的后端设置到白名单中 config.xml file。

Then set up your backend to the whitelist at the config.xml file.

<allow-intent href="*://*api.parse.com/*"/>

这篇关于XMLHttpRequest在应用程序上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆