I spend already some hours on this problem and cannot find solution. I have the following service on the webpage (kohana 3.2):
public function action_test() {
$data = file_get_contents('php://input');
$json = json_decode($data);
$t = array();
$t[Utils::$KEY_LOGIN] = isset($json->login) ? $json->login : arr::get($_POST, Utils::$KEY_LOGIN, null);
$t[Utils::$KEY_PASSWORD] = isset($json->password) ? $json->password : arr::get($_POST, Utils::$KEY_PASSWORD, null);
$returned = array("success" => true);
$returned = array_merge($returned, array("login" => $t[Utils::$KEY_LOGIN]));
$this->auto_render = FALSE;
ob_clean();
$this->request->headers['Content-Type'] = "application/json";
$this->response->body(json_encode($returned));
}
And the form to ask the service:
<html>
<head>
<meta charset="utf-8" />
<script type="text/javascript" src="//media/js/jquery-1.6.2.min.js"> </script>
<script type="text/javascript" src="//media/js/jquery-ui.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#login_sb").click(function() {
//var action = 'http://www.aaa.pl/clientservices/test';
var action = "http://localhost/aaa/clientservices/test";
$.ajax({
url : action,
type : "post",
dataType : "json",
cache : "false",
timeout: 8000,
data : {
'login': 'login@wp.pl'
},
success : function(data) {
alert(data);
if(data.success) {
alert(data.login);
}
}
});
//
return false;
});
});
</script>
</head>
<body>
<form id="login_form" method="post">
<input type="submit" value="login" id="login_sb"/>
</form>
</body>
When I call the local service everything works ok. But when I am trying to call it by Ajax remotely - it doesn't work. It also works when I manually send the form. Please help, cause I don't have any new ideas what is going wrong.