I am trying send post data to a server script mail.php
with my ionic app.
But the 'data' argument in the function handleError
is null
...
Can you help me fix this?
Can it be a Content Security Protocol issue? Because I am not sure what to use here... I need to communicate with boardlineapp.com and use FB and Google Single Sign In.
controllers.js:
sendToServer.f(data).success(handleSuccess).error(handleError);
function handleSuccess(data , textStatus, jqXHR ) {
console.log("Message successfully sent");
$("#mypanel").panel( "close" );
}
function handleError(data , textStatus, jqXHR ) {
console.log("Error when sending the message : ");
console.log(data);
console.log(data.response);
console.log(textStatus);
console.log(jqXHR);
alert("The message could not be sent. Sorry for the inconvenience.");
};
services.js:
.service('sendToServer', function sendToServerFactory($http) {
this.f = function(dataToSend) {
return $http({
url: 'http://id:password@boardlineapp.com/app/mail.php',
method: "POST",
data: dataToSend
});
}
})
mail.php:
<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: GET, POST");
header("Access-Control-Allow-Headers: *");
if($_POST) {
$userEmail=$_POST['userEmail'];
$subject=$_POST['subject'];
$destEmail=$_POST['destEmail'];
$body=$_POST['body'];
mail($destEmail, $subject, $body, "From:" . $userEmail);
#this bit doesn't work
# $response = mail($destEmail, $subject, $body, "From:" . $userEmail);
# echo $response;
# exit();
}
?>
Console error:
error TypeError: Cannot read property 'response' of null
at handleError (http://192.168.0.11:8100/js/services.js:201:27)
XMLHttpRequest cannot load http://boardlineapp.com/app/mail.php.
Response to preflight request doesn't pass access control check: The
'Access-Control-Allow-Origin' header contains multiple values '*, *',
but only one is allowed. Origin 'http://192.168.0.11:8100' is
therefore not allowed access.
config.xml:
<access origin="*"/>
<allow-navigation href="*"/>
<allow-intent href="*"/>