Cross Domain Error

Hi,

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 ‘http://www.corsproxy.com/’ 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 http://enable-cors.org/server_apache.html but it does not seem to work.

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

            .success(function(data) {
                console.log(data);cib
                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:

Regards,

1 Like

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.