Cross Domain Error



Does anyone know how to send data to an external server using AJAX without running into Cross Domain issues?

I am building an Ionic Application that connects my client application to an AWS server (EC2 instance) that contains PHP files and MySQL. I set up an Apache on my EC2 instance. I am having a cross domain issue when using AJAX post. I tried adding ‘’ to the AWS Public Domain but I get an error that CORS is not enabled. I followed these instructions to enable CORS on the Apache server but it does not seem to work.

$scope.process = function(){
method : ‘POST’,
url : ‘’ + ****AWS Public Domain
data : $.param($scope.formData),
headers : {‘Content-Type’ : ‘application/x-www-form-urlencoded’}

            .success(function(data) {
                if (!data.success){
                 $scope.errorUname = data.errors.uname;
                $scope.errorPword = data.error.pword;

                } else {

                    $scope.message = data.message;

P.S. I am somewhat new to web development so any help is great


Hi @asampath,

You shouldn’t have these errors on a device or simulator. They should be isolated to the web browser.

If you want to resolve in your browser you may try the following:



You can turn off cross domain in php script on your server:

header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");


Hi @asampath. It work fine on my device or emulator.


I got it to work with the php script header. I think apache did not restart correctly at first. I really appreciate all the help. Have a great holidays.


This worked. Thank you. Have a great holidays appreciate the help.