Search code examples
javascriptangularjsbackand

Backand signup returns XMLHttpRequest cannot load https://api.backand.com/user/signup


Backand return error this when I run the signUp method... enter image description here

Here's the signup method...

function signUp(firstName, lastName, email, password) {
    var canceller = $q.defer();
    var cancel = function(reason) {
      canceller.resolve(reason);
    };
    var promise = $http({
      method: 'POST',
      url: CONSTS.backandUrl + '/user/signup',
      data: {
        firstName: firstName,
        lastName: lastName,
        email: email,
        password: password
      },
      timeout: canceller.promise,
      ignoreLoadingBar: true
    });
    return {
      promise: promise,
      cancel: cancel
    };
  }

I have set the sign up and even the anonymous token as per the documentation.

function(BackandProvider, CONSTS) {
    BackandProvider.setAnonymousToken(CONSTS.anonymousToken);
    BackandProvider.setSignUpToken(CONSTS.signUpToken);
    BackandProvider.setAppName(CONSTS.appName);
}

Am I missing something? Would appreciate a point in the right direction.


Solution

  • This is a common issue for ajax calls through javascript. It happens because cross domain requests are not permitted through javascript ajax calls. In your case you are doing a request from domain localhost to api.backend.com. Browser checks if the server you are requesting has a header Access-Control-Allow- Origin set in the response headers. If not present, or the value of the header doesn't contain your domain in the list, then browser blocks the request.

    To overcome this there are two ways

    1. Access-Control-Allow-Origin Response header should be set at your backend API end to allow your domain to make requests to API. Example(This example is for java component on server side. Similarly it's applicable for other server side languages as well)

    Or

    1. To bypass this you have to use JSONP