Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XMLHttpRequest failed on App

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);
  }
});

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:

enter image description here

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).

like image 742
Fabricio Buzeto Avatar asked May 20 '15 20:05

Fabricio Buzeto


People also ask

How do I fix XMLHttpRequest error?

To Solve Flutter Web getting 'XMLHttpRequest' error while making HTTP call Error Most cases of this error just add Access-Control-Allow-Origin value in the header might resolve the issue. Just make sure to replace all Underscore by Dash.

What is XMLHttpRequest error?

This error is a Javascript error and it can be inspected from AndroidStudio terminal or from the browser console. If you run into this problem it means that the requests to the API server are failing due to a CORS error.


1 Answers

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.

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

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

<allow-intent href="*://*api.parse.com/*"/>
like image 141
Fabricio Buzeto Avatar answered Nov 15 '22 08:11

Fabricio Buzeto